<!DOCTYPE html>
<html lang=en>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>刻意练习 | Hexo</title>
  <script src="/js/jQuery.md5.js"></script>
  <script>
    
    (function(){
      localStorage.setItem('userinfo',hex_md5('123chen'))
      
      var localData = localStorage.getItem("userinfo");
      // var localState = localStorage.getItem("state");
        if(localStorage.getItem("state") === null){
          var reason = window.prompt('请输入访问密码');
          // var promptVal = window.prompt('请输入访问密码');
          if(reason){
              //填写内容并“确定”
              var md5Prompt = hex_md5(reason)
              //点击的是“确定” 
              if (localData !== md5Prompt){
                alert('密码错误！');
                // history.back();
                location.replace(location.href); 
              }else{
                // alert('0123');
                localStorage.setItem('state',"1")
              }
          }
          else if(reason === ""){
              //未填写但“确定”
              location.replace(location.href); 
          }
          else{
            //“取消”事件
            location.replace(location.href); 
          }
        }

    })();
  </script>
 <link rel="alternate" href="/atom.xml" data="123chen" type="application/atom+xml">
  <meta name="description" content="刻意练习Git 基础篇  第一关  12git commitgit commit  第二关  123&#x2F;&#x2F; 创建一个名为 bugFix 的新分支，然后切换过去。git branch bugFixgit checkout bugFix  第三关  123456789101112&#x2F;&#x2F; 创建新分支 bugFixgit branch bugFix&#x2F;&#x2F; 用 git checkout bugFix 命令切换到该">
<meta property="og:type" content="article">
<meta property="og:title" content="刻意练习">
<meta property="og:url" content="http://yoursite.com/20120/03/27/05/WEB/%E5%88%BB%E6%84%8F%E7%BB%83%E4%B9%A0/index.html">
<meta property="og:site_name" content="学习的敌人是自己的满足，要认真学习一点东西，必须从不自满开始。对自己，“学而不厌”，对人家，“诲人不倦”，我们应取这种态度。">
<meta property="og:description" content="刻意练习Git 基础篇  第一关  12git commitgit commit  第二关  123&#x2F;&#x2F; 创建一个名为 bugFix 的新分支，然后切换过去。git branch bugFixgit checkout bugFix  第三关  123456789101112&#x2F;&#x2F; 创建新分支 bugFixgit branch bugFix&#x2F;&#x2F; 用 git checkout bugFix 命令切换到该">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="+020120-03-27T01:12:57.000Z">
<meta property="article:modified_time" content="2020-05-08T14:10:35.640Z">
<meta property="article:author" content="溟海">
<meta property="article:tag" content="练习">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="http://yoursite.com/20120/03/27/05/WEB/%E5%88%BB%E6%84%8F%E7%BB%83%E4%B9%A0/index.html">
  
    <link rel="alternate" href="/atom.xml" title="学习的敌人是自己的满足，要认真学习一点东西，必须从不自满开始。对自己，“学而不厌”，对人家，“诲人不倦”，我们应取这种态度。" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.2.0"></head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/chen08" target="_blank">
          <img class="img-circle img-rotate" src="/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">溟海</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Web Developer &amp; Designer</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Guangzhou, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="Search" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="Type something..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
          <!-- . -->
        
        
          <li class="menu-item menu-item-home">
            <a href="/.">
              
              <i class="icon icon-home-fill"></i>
              
              <span class="menu-title">Home</span>
            </a>
          </li>
        


        
          <!-- archives -->
        
        
          <li class="menu-item menu-item-archives">
            <a href="/archives">
              
              <i class="icon icon-archives-fill"></i>
              
              <span class="menu-title">Archives</span>
            </a>
          </li>
        


        
          <!-- categories -->
        
        
          <li class="menu-item menu-item-categories">
            <a href="/categories">
              
              <i class="icon icon-folder"></i>
              
              <span class="menu-title">Categories</span>
            </a>
          </li>
        


        
          <!-- tags -->
        
        
          <li class="menu-item menu-item-tags">
            <a href="/tags">
              
              <i class="icon icon-tags"></i>
              
              <span class="menu-title">Tags</span>
            </a>
          </li>
        


        
          <!-- repository -->
        
        
          <li class="menu-item menu-item-repository">
            <a href="/repository">
              
              <i class="icon icon-project"></i>
              
              <span class="menu-title">Repository</span>
            </a>
          </li>
        


        
          <!-- books -->
        
        
          <li class="menu-item menu-item-books">
            <a href="/books">
              
              <i class="icon icon-book-fill"></i>
              
              <span class="menu-title">Books</span>
            </a>
          </li>
        


        
          <!-- links -->
        
        
          <li class="menu-item menu-item-links">
            <a href="/links">
              
              <i class="icon icon-friendship"></i>
              
              <span class="menu-title">Links</span>
            </a>
          </li>
        


        
          <!-- about -->
        
        
          <li class="menu-item menu-item-about">
            <a href="/about">
              
              <i class="icon icon-cup-fill"></i>
              
              <span class="menu-title">About</span>
            </a>
          </li>
        


        
          <!-- navigation/webstack/index.html -->
        
        
          <li class="menu-item menu-item-navigation">
            <a href="/navigation/webstack/index.html">
              
              <i class="icon icon-delicious"></i>
              
              <span class="menu-title">Navigation</span>
            </a>
          </li>
        


        
          <!-- navigation/webstack/word.html -->
        
        
          <li style="display: none;" class="menu-item menu-item-fixed">
            <a href="/navigation/webstack/word.html">
              
              <i class="icon icon-delicious"></i>
              
              <span class="menu-title">menu.fixed</span>
            </a>
          </li>
        


        
      </ul>

      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/cofess" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://weibo.com/cofess" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="https://twitter.com/iwebued" target="_blank" title="Twitter" data-toggle=tooltip data-placement=top><i class="icon icon-twitter"></i></a></li>
        
        <li><a href="https://www.behance.net/cofess" target="_blank" title="Behance" data-toggle=tooltip data-placement=top><i class="icon icon-behance"></i></a></li>
        
        <li><a href="/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">Board</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">Categories</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/1-WEB%E5%89%8D%E7%AB%AF/">1.WEB前端</a><span class="category-list-count">15</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/2-%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/">2.编程语言</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/3-%E4%BA%A7%E5%93%81%E8%AE%BE%E8%AE%A1/">3.产品设计</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/4-%E7%AE%A1%E7%90%86%E8%90%A5%E9%94%80/">4.管理营销</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/5-%E6%8A%80%E8%83%BD%E6%8F%90%E5%8D%87/">5.技能提升</a><span class="category-list-count">16</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/6-%E8%AF%BB%E4%B9%A6%E6%80%BB%E7%BB%93/">6.读书总结</a><span class="category-list-count">8</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Tags</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/" rel="tag">JavaScript</a><span class="tag-list-count">15</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" rel="tag">JavaScript设计模式</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Office/" rel="tag">Office</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/PHP/" rel="tag">PHP</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%86%99%E4%BD%9C/" rel="tag">写作</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%9F%BA%E9%87%91/" rel="tag">基金</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%AD%A6%E4%B9%A0/" rel="tag">学习</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B7%A5%E4%BD%9C/" rel="tag">工作</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%80%9D%E8%80%83/" rel="tag">思考</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%B8%85%E5%8D%95/" rel="tag">清单</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%9B%AE%E6%A0%87/" rel="tag">目标</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BB%83%E4%B9%A0/" rel="tag">练习</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%8B%B1%E8%AF%AD/" rel="tag">英语</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AE%A1%E5%88%92/" rel="tag">计划</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AF%AD%E6%B3%95/" rel="tag">语法</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%9A%8F%E7%AC%94/" rel="tag">随笔</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%9D%A2%E8%AF%95/" rel="tag">面试</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget-body tagcloud">
      <a href="/tags/JavaScript/" style="font-size: 14px;">JavaScript</a> <a href="/tags/JavaScript%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" style="font-size: 13px;">JavaScript设计模式</a> <a href="/tags/Office/" style="font-size: 13.33px;">Office</a> <a href="/tags/PHP/" style="font-size: 13.33px;">PHP</a> <a href="/tags/%E5%86%99%E4%BD%9C/" style="font-size: 13.17px;">写作</a> <a href="/tags/%E5%9F%BA%E9%87%91/" style="font-size: 13.17px;">基金</a> <a href="/tags/%E5%AD%A6%E4%B9%A0/" style="font-size: 13px;">学习</a> <a href="/tags/%E5%B7%A5%E4%BD%9C/" style="font-size: 13px;">工作</a> <a href="/tags/%E6%80%9D%E8%80%83/" style="font-size: 13px;">思考</a> <a href="/tags/%E6%B8%85%E5%8D%95/" style="font-size: 13px;">清单</a> <a href="/tags/%E7%9B%AE%E6%A0%87/" style="font-size: 13px;">目标</a> <a href="/tags/%E7%BB%83%E4%B9%A0/" style="font-size: 13px;">练习</a> <a href="/tags/%E8%8B%B1%E8%AF%AD/" style="font-size: 13.67px;">英语</a> <a href="/tags/%E8%AE%A1%E5%88%92/" style="font-size: 13.17px;">计划</a> <a href="/tags/%E8%AF%AD%E6%B3%95/" style="font-size: 13.5px;">语法</a> <a href="/tags/%E9%9A%8F%E7%AC%94/" style="font-size: 13.83px;">随笔</a> <a href="/tags/%E9%9D%A2%E8%AF%95/" style="font-size: 13px;">面试</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">Archive</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/20120/04/">April 20120</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/20120/03/">March 20120</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/05/">May 2020</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/04/">April 2020</a><span class="archive-list-count">12</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2020/03/">March 2020</a><span class="archive-list-count">14</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/5-%E6%8A%80%E8%83%BD%E6%8F%90%E5%8D%87/">5.技能提升</a>
              </p>
              <p class="item-title">
                <a href="/20120/04/21/05/fund/%E5%9F%BA%E9%87%91%E5%9F%BA%E7%A1%80/" class="title">基金基础</a>
              </p>
              <p class="item-date">
                <time datetime="+020120-04-21T01:12:57.000Z" itemprop="datePublished">20120-04-21</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/5-%E6%8A%80%E8%83%BD%E6%8F%90%E5%8D%87/">5.技能提升</a>
              </p>
              <p class="item-title">
                <a href="/20120/04/21/05/study/%E5%AD%A6%E4%B9%A0/" class="title">学习</a>
              </p>
              <p class="item-date">
                <time datetime="+020120-04-21T01:12:57.000Z" itemprop="datePublished">20120-04-21</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/5-%E6%8A%80%E8%83%BD%E6%8F%90%E5%8D%87/">5.技能提升</a>
              </p>
              <p class="item-title">
                <a href="/20120/04/13/05/%E4%BB%8A%E6%97%A5%E8%AE%A1%E5%88%92/" class="title">今日计划</a>
              </p>
              <p class="item-date">
                <time datetime="+020120-04-13T01:12:57.000Z" itemprop="datePublished">20120-04-13</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/5-%E6%8A%80%E8%83%BD%E6%8F%90%E5%8D%87/">5.技能提升</a>
              </p>
              <p class="item-title">
                <a href="/20120/04/03/05/office/Excel%E5%AD%A6%E4%B9%A0/" class="title">Excel学习</a>
              </p>
              <p class="item-date">
                <time datetime="+020120-04-03T01:12:57.000Z" itemprop="datePublished">20120-04-03</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/categories/5-%E6%8A%80%E8%83%BD%E6%8F%90%E5%8D%87/">5.技能提升</a>
              </p>
              <p class="item-title">
                <a href="/20120/04/03/05/office/PPT%E5%AD%A6%E4%B9%A0/" class="title">PPT学习</a>
              </p>
              <p class="item-date">
                <time datetime="+020120-04-03T01:12:57.000Z" itemprop="datePublished">20120-04-03</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <span class="toggle-btn-absolute">
    <a class="toggle-btn" data-toggle="collapse" href="#collapseToc" aria-expanded="true" title="Catalogue" role="button">
      <i class="text-in icon icon-close"></i>
    </a>
  </span>
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">Catalogue</h3>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#刻意练习"><span class="toc-number">1.</span> <span class="toc-text">刻意练习</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Git"><span class="toc-number">1.1.</span> <span class="toc-text">Git</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#GIT-解决冲突"><span class="toc-number">1.1.1.</span> <span class="toc-text">GIT 解决冲突</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#合并分支并提交"><span class="toc-number">1.1.2.</span> <span class="toc-text">合并分支并提交</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#tmux"><span class="toc-number">1.2.</span> <span class="toc-text">tmux</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#JavaScript"><span class="toc-number">1.3.</span> <span class="toc-text">JavaScript</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#MYSQL"><span class="toc-number">1.4.</span> <span class="toc-text">MYSQL</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#表名和字段"><span class="toc-number">1.4.1.</span> <span class="toc-text">表名和字段</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#测试数据"><span class="toc-number">1.4.2.</span> <span class="toc-text">测试数据</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#练习题和sql语句"><span class="toc-number">1.4.3.</span> <span class="toc-text">练习题和sql语句</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#数据库常用SQL语句"><span class="toc-number">1.4.4.</span> <span class="toc-text">数据库常用SQL语句</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#一、创建数据库"><span class="toc-number">1.4.4.1.</span> <span class="toc-text">一、创建数据库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#二、删除数据库"><span class="toc-number">1.4.4.2.</span> <span class="toc-text">二、删除数据库</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#三、创建表"><span class="toc-number">1.4.4.3.</span> <span class="toc-text">三、创建表</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-直接创建"><span class="toc-number">1.4.4.3.1.</span> <span class="toc-text">1.直接创建</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-更具已有表创建"><span class="toc-number">1.4.4.3.2.</span> <span class="toc-text">2.更具已有表创建</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#四、删除表"><span class="toc-number">1.4.4.4.</span> <span class="toc-text">四、删除表</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#五、增加一列"><span class="toc-number">1.4.4.5.</span> <span class="toc-text">五、增加一列</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#六、基本SQL语句"><span class="toc-number">1.4.4.6.</span> <span class="toc-text">六、基本SQL语句</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#vue"><span class="toc-number">1.5.</span> <span class="toc-text">vue</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#vue-安装"><span class="toc-number">1.5.1.</span> <span class="toc-text">vue 安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#store-的用法"><span class="toc-number">1.5.2.</span> <span class="toc-text">store 的用法</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#JavaScript-1"><span class="toc-number">1.6.</span> <span class="toc-text">JavaScript</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#webpack"><span class="toc-number">1.7.</span> <span class="toc-text">webpack</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#NPM"><span class="toc-number">1.8.</span> <span class="toc-text">NPM</span></a></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <!-- 引入百度的思维导图库 -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script>
<script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
<!-- 引入百度的思维导图库 -->
<div class="content">
  <article id="post-05/WEB/刻意练习" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      刻意练习
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/20120/03/27/05/WEB/%E5%88%BB%E6%84%8F%E7%BB%83%E4%B9%A0/" class="article-date">
	  <time datetime="+020120-03-27T01:12:57.000Z" itemprop="datePublished">20120-03-27</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/categories/5-%E6%8A%80%E8%83%BD%E6%8F%90%E5%8D%87/">5.技能提升</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/tags/%E7%BB%83%E4%B9%A0/" rel="tag">练习</a>
  </span>


        

	<span class="article-read hidden-xs">
    	<i class="icon icon-eye-fill" aria-hidden="true"></i>
    	<span id="/20120/03/27/05/WEB/%E5%88%BB%E6%84%8F%E7%BB%83%E4%B9%A0/" class="leancloud_visitors"  data-flag-title="刻意练习">0</span>
    </span>

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/20120/03/27/05/WEB/%E5%88%BB%E6%84%8F%E7%BB%83%E4%B9%A0/#comments" class="article-comment-link">Comments</a></span>
        
	
		<span class="post-wordcount hidden-xs" itemprop="wordCount">Word Count: 13.6k(words)</span>
	
	
		<span class="post-readcount hidden-xs" itemprop="timeRequired">Read Count: 60(minutes)</span>
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h1 id="刻意练习"><a href="#刻意练习" class="headerlink" title="刻意练习"></a>刻意练习</h1><h2 id="Git"><a href="#Git" class="headerlink" title="Git"></a>Git</h2><ul>
<li><p>基础篇</p>
<blockquote>
<p>第一关</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git commit</span><br><span class="line">git commit</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第二关</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建一个名为 bugFix 的新分支，然后切换过去。</span></span><br><span class="line">git branch bugFix</span><br><span class="line">git checkout bugFix</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第三关</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建新分支 bugFix</span></span><br><span class="line">git branch bugFix</span><br><span class="line"><span class="comment">// 用 git checkout bugFix 命令切换到该分支</span></span><br><span class="line">git checkout bugFix</span><br><span class="line"><span class="comment">//提交一次</span></span><br><span class="line">git commit </span><br><span class="line"><span class="comment">//用 git checkout master 切换回 master</span></span><br><span class="line">git checkout master</span><br><span class="line"><span class="comment">//再提交一次</span></span><br><span class="line">git commit </span><br><span class="line"><span class="comment">//用 git merge 把 bugFix 合并到 master</span></span><br><span class="line">git merge bugFix</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第四关</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 新建并切换到 bugFix 分支</span></span><br><span class="line">git checkout -b bugFix</span><br><span class="line"><span class="comment">//提交一次</span></span><br><span class="line">git commit </span><br><span class="line"></span><br><span class="line"><span class="comment">// 切换回 master 分支再提交一次</span></span><br><span class="line">git checkout master</span><br><span class="line">git commit </span><br><span class="line"><span class="comment">// 再次切换到 bugFix 分支，rebase 到 master 上</span></span><br><span class="line">git checkout bugFix</span><br><span class="line">git rebase master</span><br></pre></td></tr></table></figure></li>
<li><p>高级篇</p>
<blockquote>
<p>第一关 HEAD</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">// git checkout C1; git checkout master; git commit; git checkout C2</span></span><br><span class="line"><span class="comment">//分离的 HEAD</span></span><br><span class="line"><span class="comment">// 分离的 HEAD 就是让其指向了某个具体的提交记录而不是分支名。在命令执行之前的状态如下所示：</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">git checkout C1</span></span><br><span class="line"><span class="comment">git checkout master</span></span><br><span class="line"><span class="comment">git commit</span></span><br><span class="line"><span class="comment">git checkout C2</span></span><br><span class="line"><span class="comment">HEAD一开始指向master，后指向C1，后指向master</span></span><br><span class="line"><span class="comment">master提交后，HEAD随着master一起移动，并继续指向master</span></span><br><span class="line"><span class="comment">后指向C2,这一步叫做"分离的HEAD状态"!!!</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//从 bugFix 分支中分离出 HEAD 并让其指向一个提交记录。</span></span><br><span class="line">git checkout bugFix</span><br><span class="line">git checkout C4</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第二关 相对引用</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 实际中，提交的节点哈希值不会是C0/C1/C2这么简单的数值，而是40位的...</span></span><br><span class="line"><span class="comment">// 所以还是用相对引用简单。</span></span><br><span class="line">git checkout master^ 寻找指定提交记录的父提交</span><br><span class="line">git checkout master^^ 寻找指定提交记录的父父提交</span><br><span class="line"></span><br><span class="line"><span class="comment">// 此外还可以把HEAD作为，相对引用的参照。</span></span><br><span class="line">git checkout HEAD^</span><br><span class="line"></span><br><span class="line"><span class="comment">// 要完成此关，切换到 bugFix 的父节点。这会进入"分离 HEAD 状态"。</span></span><br><span class="line"><span class="comment">// 答案：</span></span><br><span class="line">git checkout bugFix</span><br><span class="line">git checkout C4</span><br><span class="line">git checkout HEAD^</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第三关 相对引用2</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">git branch -f master HEAD~<span class="number">3</span></span><br><span class="line"><span class="comment">// 将master分支强制指向 HEAD 的第 3 级父提交。</span></span><br><span class="line"><span class="comment">// 答案：</span></span><br><span class="line">git checkout C1 HEAD指向C1</span><br><span class="line">git branch -f bugFix HEAD^ 分支bugFix指向HEAD的上一级</span><br><span class="line">git branch -f master C6 分支master直接指向C6</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第四关- 版本回退</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">#git reset HEAD~1</span><br><span class="line"><span class="comment">// Git 把 master 分支移回到 C1；现在我们的本地代码库根本就不知道有 C2 这个提交了。</span></span><br><span class="line"><span class="comment">// 在reset后， C2 所做的变更还在，但是处于未加入暂存区状态。</span></span><br><span class="line"></span><br><span class="line">#git revert HEAD</span><br><span class="line"><span class="comment">// 虽然在你的本地分支中使用 git reset 很方便，但是这种“改写历史”的方法对大家一起使用的远程分支是无效的！</span></span><br><span class="line"><span class="comment">// 为了撤销更改并分享给别人，我们需要使用 git revert。</span></span><br><span class="line"><span class="comment">// 在我们要撤销的提交记录后面多出一个新提交！</span></span><br><span class="line"><span class="comment">// 这是因为新提交记录 C2' 引入了更改 —— 这些更改刚好是用来撤销 C2 这个提交的。也就是说 C2' 的状态与 C1 是相同的。</span></span><br><span class="line"><span class="comment">// revert 之后就可以把你的更改推送到远程仓库与别人分享啦。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 如果C2后边还有C3,C4等等提交，C3,C4的修改不会动，仅仅是撤销C2的这次提交修改的内容！并在C4后边生成新的提交（撤销C2的修改）。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 要完成此关，分别撤销 local 分支和 pushed 分支上的最近一次提交。共需要撤销两个提交（每个分支一个）。</span></span><br><span class="line"><span class="comment">// 记住 pushed 是远程分支，local 是本地分支 —— 这么说你应该知道用分别哪种方法了吧？</span></span><br><span class="line">git reset HEAD^</span><br><span class="line">git checkout pushed</span><br><span class="line">git revert HEAD</span><br></pre></td></tr></table></figure></li>
<li><p>移动提交记录<br>“我想要把这个提交放到这里，那个提交放到刚才那个提交的后面”</p>
<blockquote>
<p>第一关 将一些提交复制到当前所在的位置（HEAD）下面。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">git cherry-pick &lt;提交号&gt;</span><br><span class="line">git cherry-pick C2 C4</span><br><span class="line"><span class="comment">// 就会把他们抓过来放到当前分支下。</span></span><br><span class="line"><span class="comment">// 答案：</span></span><br><span class="line">git cherry-pick C3 C4 C7</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第二关 图形交互式rebase</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 你不清楚你想要的提交记录的哈希值时，rebase 加参数 --interactive （-i）</span></span><br><span class="line"><span class="comment">// Git 会打开一个 UI 界面，并列出将要被复制到目标分支的备选提交记录，</span></span><br><span class="line"><span class="comment">// 它还会显示每个提交记录的哈希值和提交说明，提交说明有助于你理解这个提交进行了哪些更改。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 当 rebase UI界面打开时, 你能做3件事:</span></span><br><span class="line"><span class="comment">// #调整提交记录的顺序（通过鼠标拖放来完成）</span></span><br><span class="line"><span class="comment">// #删除你不想要的提交（点击切换 pick 的状态来完成，关闭就意味着你不想要这个提交记录）</span></span><br><span class="line"><span class="comment">// #合并提交。它允许你把多个提交记录合并成一个。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// git rebase -i HEAD~4</span></span><br><span class="line"><span class="comment">// 可以对提交记录做排序，也可以删除某些提交。</span></span><br><span class="line"><span class="comment">// （命令的动作：从master到HEAD~4，这整串分支，从HEAD~4位置复制了一份）</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 要通过本关, 做一次交互式的 rebase，整理成目标窗口中的提交顺序。</span></span><br><span class="line"><span class="comment">// 记住，你随时都可以用 undo、reset 修正错误。</span></span><br><span class="line"><span class="comment">// 答案：</span></span><br><span class="line">git rebase -i HEAD~<span class="number">4</span></span><br><span class="line"><span class="comment">// 之后删除C2，调整C4C5的顺序</span></span><br><span class="line">git rebase -i HEAD~<span class="number">4</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>杂项</p>
<blockquote>
<p>第一关 只取一个提交记录</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 本地栈式提交</span></span><br><span class="line"><span class="comment">// 我正在解决某个特别棘手的 Bug，为了便于调试而在代码中添加了一些调试命令并向控制台打印了一些信息。</span></span><br><span class="line"><span class="comment">// 这些调试和打印语句都在它们各自的提交记录里。</span></span><br><span class="line"><span class="comment">// 最后我终于找到了造成这个 Bug 的根本原因，解决掉以后觉得沾沾自喜！</span></span><br><span class="line"><span class="comment">// 最后就差把 bugFix 分支里的工作合并回 master 分支了。</span></span><br><span class="line"><span class="comment">// 你可以选择通过 fast-forward 快速合并到 master 分支上，但这样的话 master 分支就会包含我这些调试语句了。</span></span><br><span class="line"><span class="comment">// 你肯定不想这样，应该还有更好的方式……</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 实际我们只要让 Git 复制解决问题的那一个提交记录就可以了。</span></span><br><span class="line"><span class="comment">// 跟之前我们在“整理提交记录”中学到的一样，我们可以使用</span></span><br><span class="line">git rebase -i</span><br><span class="line">git cherry-pick</span><br><span class="line"><span class="comment">// 来达到目的。</span></span><br><span class="line"></span><br><span class="line">$ git rebase -i HEAD~<span class="number">3</span> 忽略debug/print分支，只把bugFix分支移动到master下</span><br><span class="line">$ git merge master 这个时候，bugFix是<span class="string">"当前分支"</span>，但master是bugFix的父节点...</span><br><span class="line"><span class="comment">// 分支已经是最新啦</span></span><br><span class="line">$ git checkout master</span><br><span class="line">$ git merge master 写错</span><br><span class="line"><span class="comment">// 分支已经是最新啦</span></span><br><span class="line">$ git merge bugFix 必须把<span class="string">"当前分支"</span>调整为master之后，再操作合并。</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第二关 提交技巧  使用rebase -i</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 你之前在 newImage 分支上进行了一次提交，然后又基于它创建了 caption 分支，然后又提交了一次。</span></span><br><span class="line"><span class="comment">// 此时你想对的某个以前的提交记录进行一些小小的调整。</span></span><br><span class="line"><span class="comment">// 比如设计师想修改一下 newImage 中图片的分辨率，尽管那个提交记录并不是最新的了。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// -&gt;先用 git rebase -i 将提交重新排序，然后把我们想要修改的提交记录挪到最前</span></span><br><span class="line"><span class="comment">// -&gt;然后用 git commit --amend 来进行一些小修改</span></span><br><span class="line"><span class="comment">// -&gt;接着再用 git rebase -i 来将他们调回原来的顺序</span></span><br><span class="line"><span class="comment">// -&gt;最后我们把 master 移到修改的最前端（用你自己喜欢的方法），就大功告成啦！</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 当然完成这个任务的方法不止上面提到的一种（我知道你在看 cherry-pick 啦），</span></span><br><span class="line"><span class="comment">// 最后有必要说明一下目标状态中的那几个' —— 我们把这个提交移动了两次，每移动一次会产生一个 '；</span></span><br><span class="line"><span class="comment">// 而 C2 上多出来的那个是我们在使用了 amend 参数提交时产生的，所以最终结果就是这样了。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 也就是说，我在对比结果的时候只会对比提交树的结构，</span></span><br><span class="line"><span class="comment">// 对于 ' 的数量上的不同，并不纳入对比范围内。</span></span><br><span class="line"><span class="comment">// 只要你的 master 分支结构与目标结构相同，我就算你通过。</span></span><br><span class="line">git rebase -i HEAD^^ 调整c2c3，得到c3<span class="string">' c2'</span></span><br><span class="line">git commit --amend （修改c2<span class="string">'，得到c2'</span><span class="string">'）</span></span><br><span class="line"><span class="string">git rebase -i HEAD^^ 调整c2'</span><span class="string">' c3'</span>，得到c2<span class="string">''</span><span class="string">' c3'</span><span class="string">'</span></span><br><span class="line"><span class="string">git checkout master</span></span><br><span class="line"><span class="string">git merge caption caption指向c3'</span><span class="string">'，合并到master</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>第三关 提交技巧 #2：使用cherry-pick实现相同效果</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git checkout master </span><br><span class="line">git cherry-pick C2 把C2转到master分支下，得到C2<span class="string">'</span></span><br><span class="line"><span class="string">git commit --amend （修改c2'</span>，得到c2<span class="string">''</span>）</span><br><span class="line">git cherry-pick C3 把C3转到master分支下（c2<span class="string">''</span>下），得到C3<span class="string">'</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>第四关 git Tag</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 相信通过前面课程的学习你已经发现了：</span></span><br><span class="line"><span class="comment">// 分支很容易被人为移动，并且当有新的提交时，它也会移动。</span></span><br><span class="line"><span class="comment">// 分支很容易被改变，大部分分支还只是临时的，并且还一直在变。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 有没有什么可以永远指向某个提交记录的标识呢，</span></span><br><span class="line"><span class="comment">// 比如软件发布新的大版本，或者是修正一些重要的 Bug 或是增加了某些新特性，</span></span><br><span class="line"><span class="comment">// 有没有比分支更好的可以永远指向这些提交的方法呢？</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 更难得的是，它们并不会随着新的提交而移动。</span></span><br><span class="line"><span class="comment">// 你也不能检出到某个标签上面进行修改提交，</span></span><br><span class="line"><span class="comment">// 它就像是提交树上的一个锚点，标识了某个特定的位置。</span></span><br><span class="line"></span><br><span class="line">git tag v1 C1</span><br><span class="line"><span class="comment">// 如果不指定C1，会加到HEAD指向的位置。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 在这个关卡中，按照目标建立两个标签，然后检出到 v1 上面，</span></span><br><span class="line"><span class="comment">// 要注意你会进到分离 HEAD 的状态————这是因为不能直接在v1 上面做 commit。</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>第五关 git describe</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Git Describe</span></span><br><span class="line"><span class="comment">// 标签在代码库中起着“锚点”的作用，</span></span><br><span class="line"><span class="comment">// Git 为此专门设计的一个命令用来描述离你最近的锚点（也就是标签）。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// Git Describe 能帮你在提交历史中移动了多次以后找到方向；</span></span><br><span class="line"><span class="comment">// 当你用 git bisect（一个查找产生 Bug 的提交记录的指令）找到某个提交记录时，</span></span><br><span class="line"><span class="comment">// 或者是当你坐在你那刚刚度假回来的同事的电脑前时，可能会用到这个命令。</span></span><br><span class="line"></span><br><span class="line">git describe 的??语法是：git describe &lt;ref&gt;</span><br><span class="line"><span class="comment">// &lt;ref&gt; 可以是任何能被 Git 识别成提交记录的引用，</span></span><br><span class="line"><span class="comment">// 如果你没有指定的话，Git 会以你目前所检出的位置（HEAD）。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 它输出的结果是这样的：</span></span><br><span class="line"><span class="comment">// &lt;tag&gt;_&lt;numCommits&gt;_g&lt;hash&gt;</span></span><br><span class="line"><span class="comment">// tag 表示的是离 ref 最近的标签</span></span><br><span class="line"><span class="comment">// numCommits 是表示这个 ref 与 tag 相差有多少次提交记录</span></span><br><span class="line"><span class="comment">// hash 表示的是你所给定的 ref 所表示的提交记录哈希值的前几位。</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 当 ref 提交记录上有某个标签时，则只输出标签名称</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>高级话题</p>
<blockquote>
<p>第一关 多分支rebase</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<blockquote>
<p>第二关 选择父提交记录</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 操作符 ^ 与 ~ 符一样，后面也可以跟一个数字。</span></span><br><span class="line"><span class="comment">// 但是该操作符后面的数字与 ~ 后面的不同，并不是用来指定向上返回几代，</span></span><br><span class="line"><span class="comment">// 而是指定合并提交记录的某个父提交。</span></span><br><span class="line"><span class="comment">// 还记得前面提到过的一个合并提交有两个父提交吧，所以遇到这样的节点时该选择哪条路径就不是很清晰了。</span></span><br><span class="line"><span class="comment">// Git 默认选择合并提交的“第一个”父提交，在操作符 ^ 后跟一个数字可以改变这一默认行为。</span></span><br><span class="line"></span><br><span class="line">git checkout HEAD~</span><br><span class="line">git checkout HEAD^<span class="number">2</span></span><br><span class="line">git checkout HEAD~<span class="number">2</span></span><br><span class="line"><span class="comment">// 链式：git checkout HEAD~^2~2</span></span><br><span class="line">git branch bugWork master^^<span class="number">2</span>^ 在那个地方创建分支</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第三关 纠缠不清的分支</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">现在我们的 master 分支是比 one、two 和 three 要多几个提交。</span><br><span class="line">出于某种原因，我们需要把 master 分支上最近的几次提交做不同的调整后，分别添加到各个的分支上。</span><br><span class="line">one 需要重新排序并删除 C5</span><br><span class="line">two 仅需要重排排序</span><br><span class="line">three 只需要提交一次。</span><br><span class="line"></span><br><span class="line">通关之后用 show solution 看看我们的答案哦。</span><br><span class="line"></span><br><span class="line"><span class="comment">// 我的：</span></span><br><span class="line">$ git checkout three</span><br><span class="line">$ git merge C2</span><br><span class="line"></span><br><span class="line">$ git checkout C1</span><br><span class="line">$ git cherry-pick C4 C3 C2</span><br><span class="line"></span><br><span class="line">$ git checkout two</span><br><span class="line">$ git cherry-pick C5</span><br><span class="line">$ git cherry-pick C4<span class="string">' C3'</span> C2<span class="string">'</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">// 答案：</span></span><br><span class="line"><span class="string">$ git checkout one</span></span><br><span class="line"><span class="string">$ git cherry-pick C4 C3 C2</span></span><br><span class="line"><span class="string">$ git checkout two</span></span><br><span class="line"><span class="string">$ git cherry-pick C5 C4 C3 C2</span></span><br><span class="line"><span class="string">$ git branch -f three C2</span></span><br><span class="line"><span class="string">// 不用merge，而是用强制指向即可。</span></span><br></pre></td></tr></table></figure>
<p>远程</p>
</li>
<li><p>Push &amp; Pull —— Git 远程仓库！</p>
<blockquote>
<p>第一关   git clone 在本地创建一个远程仓库的拷贝</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">在我们的本地仓库多了一个名为 origin/master 的分支, 这种类型的分支就叫远程分支。</span><br><span class="line"></span><br><span class="line">远程分得有一个特别的属性，在你检出时自动进入分离 HEAD 状态。</span><br><span class="line">Git 这么做是出于不能直接在这些分支上进行操作的原因, 你必须在别的地方完成你的工作, </span><br><span class="line">（更新了远程分支之后）再用远程分享你的工作成果。</span><br><span class="line"></span><br><span class="line">用 git clone 某个仓库时，Git 已经帮你把远程仓库的名称默认设置为 origin 了.</span><br><span class="line"></span><br><span class="line">git checkout origin/master</span><br><span class="line">git commit</span><br><span class="line"></span><br><span class="line">正如你所见，Git 变成了分离 HEAD 状态，当添加新的提交时 origin/master 也不会更新。</span><br><span class="line">这是因为 origin/master 只有在远程仓库中相应的分支更新了以后才会更新。</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第二关  远程分支</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git commit</span><br><span class="line">git checkout o/master</span><br><span class="line">git commit</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第三关  git fetch </p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">从远程仓库获取一次提交记录，并且远程分支origin/master会更新</span><br><span class="line">它不会更新你的 master 分支，也不会修改你磁盘上的文件。</span><br><span class="line"></span><br><span class="line">理解这一点很重要，因为许多开发人员误以为执行了 git fetch 以后，他们本地仓库就与远程仓库同步了。</span><br><span class="line">它可能已经将进行这一操作所需的所有数据都下载了下来，但是并没有修改你本地的文件。</span><br><span class="line"></span><br><span class="line">所以, 你可以将 git fetch 的理解为单纯的下载操作。</span><br><span class="line"></span><br><span class="line">git fetch</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第四关 git pull</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">用 git fetch 获取远程的数据,</span><br><span class="line">再将这些变化更新到我们的工作当中。</span><br><span class="line">git cherry-pick o/master</span><br><span class="line">git rebase o/master</span><br><span class="line">git merge o/master</span><br><span class="line">等等</span><br><span class="line"></span><br><span class="line">由于先抓取更新再合并到本地分支，这个流程很常用，</span><br><span class="line">因此 Git 提供了一个专门的命令来完成这两个操作。</span><br><span class="line">它就是 git pull。</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第五关 模拟团队合作</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">克隆一个远程仓库（用 git clone），</span><br><span class="line">再在刚创建的远程仓库中模拟一些修改，【模拟远程修改指令git fackTeamwork &lt;分支名&gt;&lt;提交次数&gt;】</span><br><span class="line">然后在你自己的本地分支上做一些提交，</span><br><span class="line">再拉取远程仓库的变更。</span><br><span class="line">这看起来像是包含了好几节的课程。</span><br><span class="line"></span><br><span class="line">$ git clone</span><br><span class="line">local branch <span class="string">"master"</span> <span class="keyword">set</span> to track remote branch "o/master"</span><br><span class="line">$ git fakeTeamwork master 2</span><br><span class="line">$ git commit</span><br><span class="line">$ git fetch</span><br><span class="line">$ git merge o/master</span><br><span class="line"></span><br><span class="line">答案:</span><br><span class="line">git clone</span><br><span class="line">git fakeTeamwork 2</span><br><span class="line">git commit</span><br><span class="line">git pull</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第六关 git push</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">git push 负责将你的变更上传到指定的远程仓库，并在远程仓库上合并你的新提交记录。</span><br><span class="line">你可以将 git push 想象成发布你成果的命令！！！</span><br><span class="line"></span><br><span class="line">注意 —— git push 不带任何参数时的行为与 Git 的一个名为 push.default 的配置有关。</span><br><span class="line">它的默认值取决于你正使用的 Git 的版本，但是在教程中我们使用的是 upstream。</span><br><span class="line">这没什么太大的影响，但是在你的项目中进行推送之前，最好检查一下这个配置。</span><br><span class="line"></span><br><span class="line">远程仓库接收了 C2，</span><br><span class="line">远程仓库中的 master 分支也被更新到指向 C2 了，</span><br><span class="line">我们的远程分支 (o/master) 也同样被更新了。</span><br><span class="line">所有的分支都同步了！</span><br><span class="line"></span><br><span class="line">答案:</span><br><span class="line">git commit</span><br><span class="line">git commit </span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第七关  远程库提交历史的偏离</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">假设你周一克隆了一个仓库，然后开始研发某个新功能。</span><br><span class="line">到周五时，你新功能开发测试完毕可以发布了。</span><br><span class="line">但是你的同事这周写了一堆代码，</span><br><span class="line">还改了许多你的功能中使用的 API，</span><br><span class="line">这些变动会导致你新开发的功能变得不可用。</span><br><span class="line">但是他们已经将那些提交推送到远程仓库了，</span><br><span class="line">因此你的工作就变成了基于项目旧版的代码，</span><br><span class="line">与远程仓库最新的代码不匹配了。</span><br><span class="line"></span><br><span class="line">这种情况下, git push 就不知道该如何操作了。</span><br><span class="line">如果你执行 git push，Git 应该让远程仓库回到星期一那天的状态吗？</span><br><span class="line">还是直接在新代码的基础上添加你的代码，</span><br><span class="line">异或由于你的提交已经过时而直接忽略你的提交？</span><br><span class="line"></span><br><span class="line">因为这情况（历史偏离）有许多的不确定性，Git 是不会允许你 push 变更的。</span><br><span class="line">实际上它会强制你先合并远程最新的代码，然后才能分享你的工作。</span><br><span class="line"></span><br><span class="line">方法：</span><br><span class="line">git fetch</span><br><span class="line">git rebase origin/master</span><br><span class="line">git push</span><br><span class="line">我们用 git fetch 更新了本地仓库中的远程分支，</span><br><span class="line">然后用 rebase 将工们的工作移动到最新的提交记录下，</span><br><span class="line">最后再用 git push 推送到远程仓库。</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">其它的方法，merge</span><br><span class="line">尽管 git merge 不会移动你的工作（它会创建新的合并提交），</span><br><span class="line">但是它会告诉 Git 你已经合并了远程仓库的所有变更。</span><br><span class="line">这是因为远程分支现在是你本地分支的祖先，</span><br><span class="line">也就是说你的提交已经包含了远程分支的所有变化。</span><br><span class="line"></span><br><span class="line">git fetch</span><br><span class="line">git merge origin/master</span><br><span class="line">git push</span><br><span class="line"></span><br><span class="line">git fetch 更新了本地仓库中的远程分支，</span><br><span class="line">然后合并了新变更到我们的本地分支（为了包含远程仓库的变更），</span><br><span class="line">最后我们用 git push 把工作推送到远程仓库</span><br><span class="line"></span><br><span class="line">简化操作：</span><br><span class="line">git pull 就是 fetch 和 merge 的简写</span><br><span class="line">git pull --rebase 就是 fetch 和 rebase 的简写！</span><br><span class="line"></span><br><span class="line">要完成本关，你需要完成以下几步：</span><br><span class="line">克隆你的仓库</span><br><span class="line">模拟一次远程提交（fakeTeamwork）</span><br><span class="line">完成一次本地提交</span><br><span class="line">用 rebase 发布你的工作</span><br><span class="line">答案:</span><br><span class="line">git clone</span><br><span class="line">git fakeTeamwork <span class="number">1</span></span><br><span class="line">git commit</span><br><span class="line">git pull --rebase</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第八关 </p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
<li><p>关于 origin 和它的周边 —— Git 远程仓库高级操作</p>
<blockquote>
<p>第一关 推送主分支</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">在大型项目中开发人员通常会在（从 master 上分出来的）特性分支上工作，工作完成后只做一次集成。这跟前面课程的描述很相像（把 side 分支推送到远程仓库），不过本节我们会深入一些.</span><br><span class="line"></span><br><span class="line">但是有些开发人员只在 master 上做 push、pull —— 这样的话 master 总是最新的，始终与远程分支 (o/master) 保持一致。</span><br><span class="line"></span><br><span class="line">对于接下来这个工作流，我们集成了两个步骤：</span><br><span class="line"></span><br><span class="line">将特性分支集成到 master 上</span><br><span class="line">推送并更新远程分支</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">这个关卡的 Boss 很厉害 —— 以下是通关提示：</span><br><span class="line"></span><br><span class="line">这里共有三个特性分支 —— side1 side2 和 side3</span><br><span class="line">我需要将这三分支按顺序推送到远程仓库</span><br><span class="line">因为远程仓库已经被更新过了，所以我们还要把那些工作合并回来</span><br><span class="line"></span><br><span class="line">$ git fetch C8拿回本地</span><br><span class="line">$ git rebase o/master side1 rebase to o/master <span class="keyword">from</span> side1</span><br><span class="line">$ git rebase side1 side2</span><br><span class="line">$ git rebase side2 side3</span><br><span class="line">$ git rebase side3 master</span><br><span class="line">快速前进...</span><br><span class="line">$ git push</span><br><span class="line"></span><br><span class="line">答案:</span><br><span class="line">git fetch</span><br><span class="line">git rebase o/master side1</span><br><span class="line">git rebase side1 side2</span><br><span class="line">git rebase side2 side3</span><br><span class="line">git rebase side3 master</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第二关 合并远程仓库</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">在开发社区里，有许多关于 merge 与 rebase 的讨论。</span><br><span class="line">以下是关于 rebase 的优缺点：</span><br><span class="line">优点: Rebase 使你的提交树变得很干净, 所有的提交都在一条线上</span><br><span class="line">缺点: Rebase 修改了提交树的历史</span><br><span class="line">比如, 提交 C1 可以被 rebase 到 C3 之后。</span><br><span class="line">这看起来 C1 中的工作是在 C3 之后进行的，</span><br><span class="line">但实际上是在 C3 之前。</span><br><span class="line">一些开发人员喜欢保留提交历史，因此更偏爱 merge。</span><br><span class="line">而其他人（比如我自己）可能更喜欢干净的提交树，于是偏爱 rebase。</span><br><span class="line"></span><br><span class="line">使用merge实现相同功能：</span><br><span class="line">$ git checkout master </span><br><span class="line">$ git pull C8拿回本地，并且origin/master指向它，master也指向它！</span><br><span class="line">快速前进...</span><br><span class="line">$ git merge side1</span><br><span class="line">$ git merge side2</span><br><span class="line">$ git merge side3</span><br><span class="line">$ git push</span><br><span class="line"></span><br><span class="line">答案:</span><br><span class="line">git checkout master</span><br><span class="line">git pull origin master</span><br><span class="line">git merge side1</span><br><span class="line">git merge side2</span><br><span class="line">git merge side3</span><br><span class="line">git push origin master</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第三关 远程追踪</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">pull 操作时, 提交记录会被先下载到 o/master 上，之后再合并到本地的 master 分支。</span><br><span class="line">隐含的合并目标由这个关联确定的。</span><br><span class="line"></span><br><span class="line">push 操作时, 我们把工作从 master 推到远程仓库中的 master 分支(同时会更新远程分支 o/master) 。</span><br><span class="line">这个推送的目的地也是由这种关联确定的！</span><br><span class="line"></span><br><span class="line">master 和 o/master 的关联关系就是由分支的“remote tracking”属性决定的。</span><br><span class="line">master 被设定为跟踪 o/master</span><br><span class="line">这意味着为 master 分支指定了推送的目的地以及拉取后合并的目标。</span><br><span class="line"></span><br><span class="line">当你克隆仓库的时候, Git 就自动帮你把这个属性设置好了。</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">有两种方法设置这个属性，</span><br><span class="line">第一种就是通过远程分支检出一个新的分支，执行:</span><br><span class="line">git checkout -b totallyNotMaster o/master</span><br><span class="line">就可以创建一个名为 totallyNotMaster 的分支，它跟踪远程分支 o/master。</span><br><span class="line"></span><br><span class="line">另一种方法就是使用：（这个命令更明确！）</span><br><span class="line">git branch -u o/master foo</span><br><span class="line">这样 foo 就会跟踪 o/master 了。</span><br><span class="line">如果当前就在 foo 分支上, 还可以省略 foo：</span><br><span class="line">git branch -u o/master</span><br><span class="line"></span><br><span class="line">答案：</span><br><span class="line">$ git checkout -b side o/master</span><br><span class="line">local branch <span class="string">"side"</span> <span class="keyword">set</span> to track remote branch "o/master"</span><br><span class="line">$ git commit</span><br><span class="line">$ git pull --rebase</span><br><span class="line">$ git push</span><br><span class="line">方法2</span><br><span class="line">git checkout -b side o/master</span><br><span class="line">git commit</span><br><span class="line">git pull --rebase</span><br><span class="line">git push</span><br><span class="line">方法3</span><br><span class="line">git branch -f side master</span><br><span class="line">git commit</span><br><span class="line">git pull --rebase</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第四关 git push 参数</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">在远程跟踪中，Git通过当前检出分支的属性来确定远程仓库以及要 push 的目的地。</span><br><span class="line">这是未指定参数时的行为，我们可以为 push 指定参数，语法是：</span><br><span class="line">git push &lt;remote&gt; <span class="xml"><span class="tag">&lt;<span class="name">place</span>&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="xml">git push origin master</span></span><br><span class="line"></span><br><span class="line"><span class="xml">切到本地仓库中的“master”分支，</span></span><br><span class="line"><span class="xml">获取所有的提交，</span></span><br><span class="line"><span class="xml">再到远程仓库“origin”中找到“master”分支，</span></span><br><span class="line"><span class="xml">将远程仓库中没有的提交记录都添加上去，</span></span><br><span class="line"><span class="xml">搞定之后告诉我。</span></span><br><span class="line"></span><br><span class="line"><span class="xml">“place”参数告诉 Git 提交记录来自于 master, 要推送到远程仓库中的 master。</span></span><br><span class="line"><span class="xml">它实际就是要同步的两个仓库的位置。</span></span><br><span class="line"></span><br><span class="line"><span class="xml">例子：</span></span><br><span class="line"><span class="xml">git checkout C0</span></span><br><span class="line"><span class="xml">git push</span></span><br><span class="line"><span class="xml">命令失败了，什么也没有发生!</span></span><br><span class="line"><span class="xml">因为检出 HEAD 没有跟踪任何分支。</span></span><br><span class="line"><span class="xml">git checkout C0</span></span><br><span class="line"><span class="xml">git push origin master</span></span><br><span class="line"><span class="xml">可以的</span></span><br><span class="line"></span><br><span class="line"><span class="xml">答案</span></span><br><span class="line"><span class="xml">git push origin master</span></span><br><span class="line"><span class="xml">git push origin foo</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>第五关 git push 参数2</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">如果来源和去向分支的名称不同呢？</span><br><span class="line">比如你想把本地的 foo 分支推送到远程仓库中的 bar 分支。</span><br><span class="line"></span><br><span class="line">git push origin &lt;source&gt;:<span class="xml"><span class="tag">&lt;<span class="name">destination</span>&gt;</span></span></span><br><span class="line"><span class="xml">这个参数实际的值是个 refspec，“refspec” 是一个自造的词，</span></span><br><span class="line"><span class="xml">意思是 Git 能识别的位置（比如分支 foo 或者 HEAD~1）</span></span><br><span class="line"></span><br><span class="line"><span class="xml">如果你要推送到的目的分支不存在，Git 会在远程仓库中根据你提供的名称帮你创建这个分支！</span></span><br><span class="line"></span><br><span class="line"><span class="xml">$ git push origin master^:foo</span></span><br><span class="line"><span class="xml">$ git push origin foo:master</span></span><br><span class="line"></span><br><span class="line"><span class="xml">答案:</span></span><br><span class="line"><span class="xml">git push origin foo:master</span></span><br><span class="line"><span class="xml">git push origin master^:foo</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>第六关 Git Fetch的参数</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">git fetch 的参数和 git push 极其相似。</span><br><span class="line">他们的概念是相同的，只是方向相反罢了（因为现在你是下载，而非上传）</span><br><span class="line"></span><br><span class="line">git fetch origin foo</span><br><span class="line">为何 Git 会将新提交放到 o/foo 而不是放到我本地的 foo 分支呢？</span><br><span class="line">本例中 Git 做了一些特殊处理，因为你可能在 foo 分支上的工作还未完成，你也不想弄乱它。</span><br><span class="line">fetch它不会更新你的本地的非远程分支, 只是下载提交记录</span><br><span class="line">（这样, 你就可以对远程分支进行检查或者合并了）。</span><br><span class="line"></span><br><span class="line">如果你觉得直接更新本地分支很爽，那你就用冒号分隔的 refspec 吧。</span><br><span class="line">不过，你不能在当前检出的分支上干这个事，但是其它分支是可以的。</span><br><span class="line">注意：</span><br><span class="line">source 现在指的是远程仓库中的位置，而 &lt;destination&gt; 才是要放置提交的本地仓库的位置。</span><br><span class="line">它与 git push 刚好相反，这是可以讲的通的，因为我们在往相反的方向传送数据。</span><br><span class="line">理论上虽然行的通，但开发人员很少这么做。</span><br><span class="line"></span><br><span class="line">如果参数分支不存在，就会新建。</span><br><span class="line">如果 git fetch 没有参数，它会下载所有的提交记录到各个远程分支……</span><br><span class="line"></span><br><span class="line">答案：</span><br><span class="line">$ git fetch origin master~<span class="number">1</span>:foo</span><br><span class="line">$ git fetch origin foo:master</span><br><span class="line">$ git checkout foo</span><br><span class="line">$ git merge master</span><br><span class="line"></span><br><span class="line">答案:</span><br><span class="line">git fetch origin master^:foo</span><br><span class="line">git fetch origin foo:master</span><br><span class="line">git checkout foo</span><br><span class="line">git merge master</span><br><span class="line">或者</span><br><span class="line">git pull origin master^:foo</span><br><span class="line">git pull origin foo:master</span><br><span class="line">git branch -f foo</span><br><span class="line">git checkout foo</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第七关 没有source的source</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">如果 push 空 &lt;source&gt; 到远程仓库会如何呢？它会删除远程仓库中的分支！</span><br><span class="line">git push origin :foo</span><br><span class="line">我们通过给 push 传空值 source，成功删除了远程仓库中的 foo 分支, 这真有意思...</span><br><span class="line"></span><br><span class="line">如果 fetch 空 &lt;source&gt; 到本地，会在本地创建一个新分支。</span><br><span class="line">git fetch origin :bar</span><br><span class="line">很神奇吧！但无论怎么说, 这就是 Git！</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">答案</span><br><span class="line">git pull origin :bar</span><br><span class="line">git push origin :foo</span><br></pre></td></tr></table></figure>
<blockquote>
<p>第八关 </p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line">答案:</span><br><span class="line">git pull origin bar:foo</span><br><span class="line">git pull origin master:side</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="GIT-解决冲突"><a href="#GIT-解决冲突" class="headerlink" title="GIT 解决冲突"></a>GIT 解决冲突</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&#x2F;&#x2F;提交的时候报错，代码有冲突</span><br><span class="line">$ git push</span><br><span class="line">To https:&#x2F;&#x2F;gitee.com&#x2F;gitcdh&#x2F;gitStudy.git</span><br><span class="line"> ! [rejected]        master -&gt; master (fetch first)</span><br><span class="line">error: failed to push some refs to &#39;https:&#x2F;&#x2F;gitee.com&#x2F;gitcdh&#x2F;gitStudy.git&#39;</span><br><span class="line">hint: Updates were rejected because the remote contains work that you do</span><br><span class="line">hint: not have locally. This is usually caused by another repository pushing</span><br><span class="line">hint: to the same ref. You may want to first integrate the remote changes</span><br><span class="line">hint: (e.g., &#39;git pull ...&#39;) before pushing again.</span><br><span class="line">hint: See the &#39;Note about fast-forwards&#39; in &#39;git push --help&#39; for details.</span><br><span class="line"></span><br><span class="line">解决办法</span><br><span class="line">git pull origin master </span><br><span class="line"></span><br><span class="line">git push -u origin master &#x2F;&#x2F;把本地仓库的文件推送到远程仓库wen</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">正确步骤： </span><br><span class="line">1. git init &#x2F;&#x2F;初始化仓库</span><br><span class="line"></span><br><span class="line">git add .(文件name) &#x2F;&#x2F;添加文件到本地仓库</span><br><span class="line"></span><br><span class="line">git commit -m “first commit” &#x2F;&#x2F;添加文件描述信息</span><br><span class="line"></span><br><span class="line">git remote add origin + 远程仓库地址 &#x2F;&#x2F;链接远程仓库，创建主分支</span><br><span class="line"></span><br><span class="line">git pull origin master &#x2F;&#x2F; 把本地仓库的变化连接到远程仓库主分支</span><br><span class="line"></span><br><span class="line">git push -u origin master &#x2F;&#x2F;把本地仓库的文件推送到远程仓库</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">【Git】pull遇到错误：error: Your local changes to the following files would be overwritten by merge:</span><br><span class="line"></span><br><span class="line">首先取决于你是否想要保存本地修改。（是 &#x2F;否）</span><br><span class="line"></span><br><span class="line">是</span><br><span class="line">别急我们有如下三部曲</span><br><span class="line"></span><br><span class="line">&#96;&#96;&#96;javascrio</span><br><span class="line"></span><br><span class="line">git stash的时候会把你本地快照，然后git pull 就不会阻止你了，pull完之后这时你的代码并没有保留你的修改。惊了！ 别急，我们之前好像做了什么</span><br><span class="line">STASH</span><br><span class="line">这时候执行git stash pop你去本地看会发现发生冲突的本地修改还在，这时候你该commit push啥的就悉听尊便了。</span><br><span class="line"></span><br><span class="line">否</span><br><span class="line">既然不想保留本地的修改，那好办。直接将本地的状态恢复到上一个commit id 。然后用远程的代码直接覆盖本地就好了。</span><br><span class="line"></span><br><span class="line">git reset --hard </span><br><span class="line">git pull origin master</span><br><span class="line"></span><br><span class="line">问题</span><br><span class="line">error: Pulling is not possible because you have unmerged files.</span><br><span class="line">hint: Fix them up in the work tree, and then use &#39;git add&#x2F;rm &lt;file&gt;&#39;</span><br><span class="line">hint: as appropriate to mark resolution and make a commit.</span><br><span class="line">fatal: Exiting because of an unresolved conflict.</span><br><span class="line"></span><br><span class="line">解决办法</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;注释：提交本地代码到工作区</span><br><span class="line">&#x2F;&#x2F;注释：如果有冲突，先解决冲突合并代码，然后提交</span><br><span class="line">&#x2F;&#x2F;注释：如果代码上没有冲突，但是提交的时候git提醒有冲突，那么先关闭编辑器，然后编译代码找到冲突，最后手动合并代码解决冲突</span><br><span class="line">git add .</span><br><span class="line">git commit -m &#39;提交本地代码并且获取最新代码&#39;</span><br><span class="line">&#x2F;&#x2F;注释：获取源dev分支最新代码</span><br><span class="line">git pull origin dev</span><br><span class="line">&#x2F;&#x2F;注释：如有冲突就解决冲突</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">常用方法</span><br><span class="line">git pull orgin master</span><br><span class="line">git add .</span><br><span class="line">git commit -m &quot;&quot;</span><br><span class="line">git pull orgin master</span><br><span class="line">git add .</span><br><span class="line">git commit -m &quot;&quot;</span><br><span class="line">git pull orgin master</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>


<h3 id="合并分支并提交"><a href="#合并分支并提交" class="headerlink" title="合并分支并提交"></a>合并分支并提交</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="tmux"><a href="#tmux" class="headerlink" title="tmux"></a>tmux</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br></pre></td><td class="code"><pre><span class="line">注意：本文内容适用于 Tmux 2.3 及以上的版本，但是绝大部分的特性低版本也都适用，鼠标支持、VI 模式、插件管理在低版本可能会与本文不兼容。</span><br><span class="line"></span><br><span class="line"># Tmux 快捷键 &amp; 速查表 &amp; 简明教程</span><br><span class="line"></span><br><span class="line">启动新会话：</span><br><span class="line"></span><br><span class="line">    tmux [new -s 会话名 -n 窗口名]</span><br><span class="line"></span><br><span class="line">恢复会话：</span><br><span class="line"></span><br><span class="line">    tmux at [-t 会话名]</span><br><span class="line"></span><br><span class="line">列出所有会话：</span><br><span class="line"></span><br><span class="line">    tmux ls</span><br><span class="line"></span><br><span class="line">&lt;a name&#x3D;&quot;killSessions&quot;&gt;&lt;&#x2F;a&gt;关闭会话：</span><br><span class="line"></span><br><span class="line">    tmux kill-session -t 会话名</span><br><span class="line"></span><br><span class="line">&lt;a name&#x3D;&quot;killAllSessions&quot;&gt;&lt;&#x2F;a&gt;关闭所有会话：</span><br><span class="line"></span><br><span class="line">    tmux ls | grep : | cut -d. -f1 | awk &#39;&#123;print substr($1, 0, length($1)-1)&#125;&#39; | xargs kill</span><br><span class="line"></span><br><span class="line"># 在 Tmux 中，按下 Tmux 前缀 &#96;ctrl+b&#96;，然后：</span><br><span class="line"></span><br><span class="line">## 会话</span><br><span class="line"></span><br><span class="line">    :new&lt;回车&gt;  启动新会话</span><br><span class="line">    s           列出所有会话</span><br><span class="line">    $           重命名当前会话</span><br><span class="line"></span><br><span class="line">## &lt;a name&#x3D;&quot;WindowsTabs&quot;&gt;&lt;&#x2F;a&gt;窗口 (标签页)</span><br><span class="line"></span><br><span class="line">    c  创建新窗口</span><br><span class="line">    w  列出所有窗口</span><br><span class="line">    n  后一个窗口</span><br><span class="line">    p  前一个窗口</span><br><span class="line">    f  查找窗口</span><br><span class="line">    ,  重命名当前窗口</span><br><span class="line">    &amp;  关闭当前窗口</span><br><span class="line"></span><br><span class="line">## 调整窗口排序</span><br><span class="line"></span><br><span class="line">    swap-window -s 3 -t 1  交换 3 号和 1 号窗口</span><br><span class="line">    swap-window -t 1       交换当前和 1 号窗口</span><br><span class="line">    move-window -t 1       移动当前窗口到 1 号</span><br><span class="line"></span><br><span class="line">## &lt;a name&#x3D;&quot;PanesSplits&quot;&gt;&lt;&#x2F;a&gt;窗格（分割窗口） </span><br><span class="line"></span><br><span class="line">    %  垂直分割</span><br><span class="line">    &quot;  水平分割</span><br><span class="line">    o  交换窗格</span><br><span class="line">    x  关闭窗格</span><br><span class="line">    ⍽  左边这个符号代表空格键 - 切换布局</span><br><span class="line">    q 显示每个窗格是第几个，当数字出现的时候按数字几就选中第几个窗格</span><br><span class="line">    &#123; 与上一个窗格交换位置</span><br><span class="line">    &#125; 与下一个窗格交换位置</span><br><span class="line">    z 切换窗格最大化&#x2F;最小化</span><br><span class="line"></span><br><span class="line">## &lt;a name&#x3D;&quot;syncPanes&quot;&gt;&lt;&#x2F;a&gt;同步窗格</span><br><span class="line"></span><br><span class="line">这么做可以切换到想要的窗口，输入 Tmux 前缀和一个冒号呼出命令提示行，然后输入：</span><br><span class="line"></span><br><span class="line">&#96;&#96;&#96;</span><br><span class="line">:setw synchronize-panes</span><br><span class="line">&#96;&#96;&#96;</span><br><span class="line"></span><br><span class="line">你可以指定开或关，否则重复执行命令会在两者间切换。</span><br><span class="line">这个选项值针对某个窗口有效，不会影响别的会话和窗口。</span><br><span class="line">完事儿之后再次执行命令来关闭。[帮助](http:&#x2F;&#x2F;blog.sanctum.geek.nz&#x2F;sync-tmux-panes&#x2F;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">## 调整窗格尺寸</span><br><span class="line"></span><br><span class="line">如果你不喜欢默认布局，可以重调窗格的尺寸。虽然这很容易实现，但一般不需要这么干。这几个命令用来调整窗格：</span><br><span class="line"></span><br><span class="line">    PREFIX : resize-pane -D          当前窗格向下扩大 1 格</span><br><span class="line">    PREFIX : resize-pane -U          当前窗格向上扩大 1 格</span><br><span class="line">    PREFIX : resize-pane -L          当前窗格向左扩大 1 格</span><br><span class="line">    PREFIX : resize-pane -R          当前窗格向右扩大 1 格</span><br><span class="line">    PREFIX : resize-pane -D 20       当前窗格向下扩大 20 格</span><br><span class="line">    PREFIX : resize-pane -t 2 -L 20  编号为 2 的窗格向左扩大 20 格</span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line">## 文本复制模式：</span><br><span class="line"></span><br><span class="line">按下 &#96;PREFIX-[&#96; 进入文本复制模式。可以使用方向键在屏幕中移动光标。默认情况下，方向键是启用的。在配置文件中启用 Vim 键盘布局来切换窗口、调整窗格大小。Tmux 也支持 Vi 模式。要是想启用 Vi 模式，只需要把下面这一行添加到 .tmux.conf 中：</span><br><span class="line"></span><br><span class="line">    setw -g mode-keys vi</span><br><span class="line"></span><br><span class="line">启用这条配置后，就可以使用 h、j、k、l 来移动光标了。</span><br><span class="line"></span><br><span class="line">想要退出文本复制模式的话，按下回车键就可以了。然后按下 &#96;PREFIX-]&#96; 粘贴刚才复制的文本。</span><br><span class="line"></span><br><span class="line">一次移动一格效率低下，在 Vi 模式启用的情况下，可以辅助一些别的快捷键高效工作。</span><br><span class="line"></span><br><span class="line">例如，可以使用 w 键逐词移动，使用 b 键逐词回退。使用 f 键加上任意字符跳转到当前行第一次出现该字符的位置，使用 F 键达到相反的效果。</span><br><span class="line"></span><br><span class="line">    vi             emacs        功能</span><br><span class="line">    ^              M-m          反缩进</span><br><span class="line">    Escape         C-g          清除选定内容</span><br><span class="line">    Enter          M-w          复制选定内容</span><br><span class="line">    j              Down         光标下移</span><br><span class="line">    h              Left         光标左移</span><br><span class="line">    l              Right        光标右移</span><br><span class="line">    L                           光标移到尾行</span><br><span class="line">    M              M-r          光标移到中间行</span><br><span class="line">    H              M-R          光标移到首行</span><br><span class="line">    k              Up           光标上移</span><br><span class="line">    d              C-u          删除整行</span><br><span class="line">    D              C-k          删除到行末</span><br><span class="line">    $              C-e          移到行尾</span><br><span class="line">    :              g            前往指定行</span><br><span class="line">    C-d            M-Down       向下滚动半屏</span><br><span class="line">    C-u            M-Up         向上滚动半屏</span><br><span class="line">    C-f            Page down    下一页</span><br><span class="line">    w              M-f          下一个词</span><br><span class="line">    p              C-y          粘贴</span><br><span class="line">    C-b            Page up      上一页</span><br><span class="line">    b              M-b          上一个词</span><br><span class="line">    q              Escape       退出</span><br><span class="line">    C-Down or J    C-Down       向下翻</span><br><span class="line">    C-Up or K      C-Up         向下翻</span><br><span class="line">    n              n            继续搜索</span><br><span class="line">    ?              C-r          向前搜索</span><br><span class="line">    &#x2F;              C-s          向后搜索</span><br><span class="line">    0              C-a          移到行首</span><br><span class="line">    Space          C-Space      开始选中</span><br><span class="line">                   C-t          字符调序</span><br><span class="line"></span><br><span class="line">## 杂项：</span><br><span class="line"></span><br><span class="line">    d  退出 tmux（tmux 仍在后台运行）</span><br><span class="line">    t  窗口中央显示一个数字时钟</span><br><span class="line">    ?  列出所有快捷键</span><br><span class="line">    :  命令提示符</span><br><span class="line"></span><br><span class="line">## 配置选项：</span><br><span class="line"></span><br><span class="line">    # 鼠标支持 - 设置为 on 来启用鼠标(与 2.1 之前的版本有区别，请自行查阅 man page)</span><br><span class="line">    * set -g mouse on</span><br><span class="line"></span><br><span class="line">    # 设置默认终端模式为 256color</span><br><span class="line">    set -g default-terminal &quot;screen-256color&quot;</span><br><span class="line"></span><br><span class="line">    # 启用活动警告</span><br><span class="line">    setw -g monitor-activity on</span><br><span class="line">    set -g visual-activity on</span><br><span class="line"></span><br><span class="line">    # 居中窗口列表</span><br><span class="line">    set -g status-justify centre</span><br><span class="line"></span><br><span class="line">    # 最大化&#x2F;恢复窗格</span><br><span class="line">    unbind Up bind Up new-window -d -n tmp \; swap-pane -s tmp.1 \; select-window -t tmp</span><br><span class="line">    unbind Down</span><br><span class="line">    bind Down last-window \; swap-pane -s tmp.1 \; kill-window -t tmp</span><br><span class="line"></span><br><span class="line">## 参考配置文件（~&#x2F;.tmux.conf）：</span><br><span class="line"></span><br><span class="line">下面这份配置是我使用 Tmux 几年来逐渐精简后的配置，请自取。</span><br><span class="line"></span><br><span class="line">&#96;&#96;&#96;bash</span><br><span class="line"># -----------------------------------------------------------------------------</span><br><span class="line"># Tmux 基本配置 - 要求 Tmux &gt;&#x3D; 2.3</span><br><span class="line"># 如果不想使用插件，只需要将此节的内容写入 ~&#x2F;.tmux.conf 即可</span><br><span class="line"># -----------------------------------------------------------------------------</span><br><span class="line"></span><br><span class="line"># C-b 和 VIM 冲突，修改 Prefix 组合键为 Control-Z，按键距离近</span><br><span class="line">set -g prefix C-z</span><br><span class="line"></span><br><span class="line">set -g base-index         1     # 窗口编号从 1 开始计数</span><br><span class="line">set -g display-panes-time 10000 # PREFIX-Q 显示编号的驻留时长，单位 ms</span><br><span class="line">set -g mouse              on    # 开启鼠标</span><br><span class="line">set -g pane-base-index    1     # 窗格编号从 1 开始计数</span><br><span class="line">set -g renumber-windows   on    # 关掉某个窗口后，编号重排</span><br><span class="line"></span><br><span class="line">setw -g allow-rename      off   # 禁止活动进程修改窗口名</span><br><span class="line">setw -g automatic-rename  off   # 禁止自动命名新窗口</span><br><span class="line">setw -g mode-keys         vi    # 进入复制模式的时候使用 vi 键位（默认是 EMACS）</span><br><span class="line"></span><br><span class="line"># -----------------------------------------------------------------------------</span><br><span class="line"># 使用插件 - via tpm</span><br><span class="line">#   1. 执行 git clone https:&#x2F;&#x2F;github.com&#x2F;tmux-plugins&#x2F;tpm ~&#x2F;.tmux&#x2F;plugins&#x2F;tpm</span><br><span class="line">#   2. 执行 bash ~&#x2F;.tmux&#x2F;plugins&#x2F;tpm&#x2F;bin&#x2F;install_plugins</span><br><span class="line"># -----------------------------------------------------------------------------</span><br><span class="line"></span><br><span class="line">setenv -g TMUX_PLUGIN_MANAGER_PATH &#39;~&#x2F;.tmux&#x2F;plugins&#39;</span><br><span class="line"></span><br><span class="line"># 推荐的插件（请去每个插件的仓库下读一读使用教程）</span><br><span class="line">set -g @plugin &#39;seebi&#x2F;tmux-colors-solarized&#39;</span><br><span class="line">set -g @plugin &#39;tmux-plugins&#x2F;tmux-pain-control&#39;</span><br><span class="line">set -g @plugin &#39;tmux-plugins&#x2F;tmux-prefix-highlight&#39;</span><br><span class="line">set -g @plugin &#39;tmux-plugins&#x2F;tmux-resurrect&#39;</span><br><span class="line">set -g @plugin &#39;tmux-plugins&#x2F;tmux-sensible&#39;</span><br><span class="line">set -g @plugin &#39;tmux-plugins&#x2F;tmux-yank&#39;</span><br><span class="line">set -g @plugin &#39;tmux-plugins&#x2F;tpm&#39;</span><br><span class="line"></span><br><span class="line"># tmux-resurrect</span><br><span class="line">set -g @resurrect-dir &#39;~&#x2F;.tmux&#x2F;resurrect&#39;</span><br><span class="line"></span><br><span class="line"># tmux-prefix-highlight</span><br><span class="line">set -g status-right &#39;#&#123;prefix_highlight&#125; #H | %a %Y-%m-%d %H:%M&#39;</span><br><span class="line">set -g @prefix_highlight_show_copy_mode &#39;on&#39;</span><br><span class="line">set -g @prefix_highlight_copy_mode_attr &#39;fg&#x3D;white,bg&#x3D;blue&#39;</span><br><span class="line"></span><br><span class="line"># 初始化 TPM 插件管理器 (放在配置文件的最后)</span><br><span class="line">run &#39;~&#x2F;.tmux&#x2F;plugins&#x2F;tpm&#x2F;tpm&#39;</span><br><span class="line"></span><br><span class="line"># -----------------------------------------------------------------------------</span><br><span class="line"># 结束</span><br><span class="line"># -----------------------------------------------------------------------------</span><br><span class="line">&#96;&#96;&#96;</span><br></pre></td></tr></table></figure>

<h2 id="JavaScript"><a href="#JavaScript" class="headerlink" title="JavaScript"></a>JavaScript</h2><h2 id="MYSQL"><a href="#MYSQL" class="headerlink" title="MYSQL"></a>MYSQL</h2><p><a href="https://github.com/Snailclimb/JavaGuide/blob/master/docs/database/MySQL.md" target="_blank" rel="noopener">MySQL/数据库知识点总结 - GitHub</a></p>
<p><a href="https://www.liaoxuefeng.com/wiki/1177760294764384/1179611432985088" target="_blank" rel="noopener">廖雪峰mysql在线练习</a></p>
<p><a href="http://sqlfiddle.com/#" target="_blank" rel="noopener">MYSQL在线练习</a></p>
<p><a href="http://sample.jimstone.com.cn/xsql/" target="_blank" rel="noopener">MYSQL练习</a></p>
<p><a href="https://sqlzoo.net" target="_blank" rel="noopener">MYSQL练习2</a></p>
<p><a href="https://sqlbolt.com/lesson/select_queries_introduction" target="_blank" rel="noopener">MYSQL练习3</a></p>
<p><a href="https://www.w3resource.com/sql-exercises/sql-retrieve-from-table.php" target="_blank" rel="noopener">MYSQL练习4</a></p>
<h3 id="表名和字段"><a href="#表名和字段" class="headerlink" title="表名和字段"></a>表名和字段</h3><ol>
<li>学生表<br>Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别</li>
<li>课程表<br>Course(c_id,c_name,t_id) – –课程编号, 课程名称, 教师编号</li>
<li>教师表<br>Teacher(t_id,t_name) –教师编号,教师姓名</li>
<li>成绩表<br>Score(s_id,c_id,s_score) –学生编号,课程编号,分数</li>
</ol>
<h3 id="测试数据"><a href="#测试数据" class="headerlink" title="测试数据"></a>测试数据</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line">--建表</span><br><span class="line">--学生表</span><br><span class="line">CREATE TABLE <span class="string">`Student`</span>(</span><br><span class="line">	<span class="string">`s_id`</span> VARCHAR(<span class="number">20</span>),</span><br><span class="line">	<span class="string">`s_name`</span> VARCHAR(<span class="number">20</span>) NOT NULL DEFAULT <span class="string">''</span>,</span><br><span class="line">	<span class="string">`s_birth`</span> VARCHAR(<span class="number">20</span>) NOT NULL DEFAULT <span class="string">''</span>,</span><br><span class="line">	<span class="string">`s_sex`</span> VARCHAR(<span class="number">10</span>) NOT NULL DEFAULT <span class="string">''</span>,</span><br><span class="line">	PRIMARY KEY(<span class="string">`s_id`</span>)</span><br><span class="line">);</span><br><span class="line">--课程表</span><br><span class="line">CREATE TABLE <span class="string">`Course`</span>(</span><br><span class="line">	<span class="string">`c_id`</span>  VARCHAR(<span class="number">20</span>),</span><br><span class="line">	<span class="string">`c_name`</span> VARCHAR(<span class="number">20</span>) NOT NULL DEFAULT <span class="string">''</span>,</span><br><span class="line">	<span class="string">`t_id`</span> VARCHAR(<span class="number">20</span>) NOT NULL,</span><br><span class="line">	PRIMARY KEY(<span class="string">`c_id`</span>)</span><br><span class="line">);</span><br><span class="line">--教师表</span><br><span class="line">CREATE TABLE <span class="string">`Teacher`</span>(</span><br><span class="line">	<span class="string">`t_id`</span> VARCHAR(<span class="number">20</span>),</span><br><span class="line">	<span class="string">`t_name`</span> VARCHAR(<span class="number">20</span>) NOT NULL DEFAULT <span class="string">''</span>,</span><br><span class="line">	PRIMARY KEY(<span class="string">`t_id`</span>)</span><br><span class="line">);</span><br><span class="line">--成绩表</span><br><span class="line">CREATE TABLE <span class="string">`Score`</span>(</span><br><span class="line">	<span class="string">`s_id`</span> VARCHAR(<span class="number">20</span>),</span><br><span class="line">	<span class="string">`c_id`</span>  VARCHAR(<span class="number">20</span>),</span><br><span class="line">	<span class="string">`s_score`</span> INT(<span class="number">3</span>),</span><br><span class="line">	PRIMARY KEY(<span class="string">`s_id`</span>,<span class="string">`c_id`</span>)</span><br><span class="line">);</span><br><span class="line">--插入学生表测试数据</span><br><span class="line">insert into Student values(<span class="string">'01'</span> , <span class="string">'赵雷'</span> , <span class="string">'1990-01-01'</span> , <span class="string">'男'</span>);</span><br><span class="line">insert into Student values(<span class="string">'02'</span> , <span class="string">'钱电'</span> , <span class="string">'1990-12-21'</span> , <span class="string">'男'</span>);</span><br><span class="line">insert into Student values(<span class="string">'03'</span> , <span class="string">'孙风'</span> , <span class="string">'1990-05-20'</span> , <span class="string">'男'</span>);</span><br><span class="line">insert into Student values(<span class="string">'04'</span> , <span class="string">'李云'</span> , <span class="string">'1990-08-06'</span> , <span class="string">'男'</span>);</span><br><span class="line">insert into Student values(<span class="string">'05'</span> , <span class="string">'周梅'</span> , <span class="string">'1991-12-01'</span> , <span class="string">'女'</span>);</span><br><span class="line">insert into Student values(<span class="string">'06'</span> , <span class="string">'吴兰'</span> , <span class="string">'1992-03-01'</span> , <span class="string">'女'</span>);</span><br><span class="line">insert into Student values(<span class="string">'07'</span> , <span class="string">'郑竹'</span> , <span class="string">'1989-07-01'</span> , <span class="string">'女'</span>);</span><br><span class="line">insert into Student values(<span class="string">'08'</span> , <span class="string">'王菊'</span> , <span class="string">'1990-01-20'</span> , <span class="string">'女'</span>);</span><br><span class="line">--课程表测试数据</span><br><span class="line">insert into Course values(<span class="string">'01'</span> , <span class="string">'语文'</span> , <span class="string">'02'</span>);</span><br><span class="line">insert into Course values(<span class="string">'02'</span> , <span class="string">'数学'</span> , <span class="string">'01'</span>);</span><br><span class="line">insert into Course values(<span class="string">'03'</span> , <span class="string">'英语'</span> , <span class="string">'03'</span>);</span><br><span class="line"></span><br><span class="line">--教师表测试数据</span><br><span class="line">insert into Teacher values(<span class="string">'01'</span> , <span class="string">'张三'</span>);</span><br><span class="line">insert into Teacher values(<span class="string">'02'</span> , <span class="string">'李四'</span>);</span><br><span class="line">insert into Teacher values(<span class="string">'03'</span> , <span class="string">'王五'</span>);</span><br><span class="line"></span><br><span class="line">--成绩表测试数据</span><br><span class="line">insert into Score values(<span class="string">'01'</span> , <span class="string">'01'</span> , <span class="number">80</span>);</span><br><span class="line">insert into Score values(<span class="string">'01'</span> , <span class="string">'02'</span> , <span class="number">90</span>);</span><br><span class="line">insert into Score values(<span class="string">'01'</span> , <span class="string">'03'</span> , <span class="number">99</span>);</span><br><span class="line">insert into Score values(<span class="string">'02'</span> , <span class="string">'01'</span> , <span class="number">70</span>);</span><br><span class="line">insert into Score values(<span class="string">'02'</span> , <span class="string">'02'</span> , <span class="number">60</span>);</span><br><span class="line">insert into Score values(<span class="string">'02'</span> , <span class="string">'03'</span> , <span class="number">80</span>);</span><br><span class="line">insert into Score values(<span class="string">'03'</span> , <span class="string">'01'</span> , <span class="number">80</span>);</span><br><span class="line">insert into Score values(<span class="string">'03'</span> , <span class="string">'02'</span> , <span class="number">80</span>);</span><br><span class="line">insert into Score values(<span class="string">'03'</span> , <span class="string">'03'</span> , <span class="number">80</span>);</span><br><span class="line">insert into Score values(<span class="string">'04'</span> , <span class="string">'01'</span> , <span class="number">50</span>);</span><br><span class="line">insert into Score values(<span class="string">'04'</span> , <span class="string">'02'</span> , <span class="number">30</span>);</span><br><span class="line">insert into Score values(<span class="string">'04'</span> , <span class="string">'03'</span> , <span class="number">20</span>);</span><br><span class="line">insert into Score values(<span class="string">'05'</span> , <span class="string">'01'</span> , <span class="number">76</span>);</span><br><span class="line">insert into Score values(<span class="string">'05'</span> , <span class="string">'02'</span> , <span class="number">87</span>);</span><br><span class="line">insert into Score values(<span class="string">'06'</span> , <span class="string">'01'</span> , <span class="number">31</span>);</span><br><span class="line">insert into Score values(<span class="string">'06'</span> , <span class="string">'03'</span> , <span class="number">34</span>);</span><br><span class="line">insert into Score values(<span class="string">'07'</span> , <span class="string">'02'</span> , <span class="number">89</span>);</span><br><span class="line">insert into Score values(<span class="string">'07'</span> , <span class="string">'03'</span> , <span class="number">98</span>);</span><br></pre></td></tr></table></figure>

<h3 id="练习题和sql语句"><a href="#练习题和sql语句" class="headerlink" title="练习题和sql语句"></a>练习题和sql语句</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br></pre></td><td class="code"><pre><span class="line">-- <span class="number">1</span>、查询<span class="string">"01"</span>课程比<span class="string">"02"</span>课程成绩高的学生的信息及课程分数	</span><br><span class="line">	</span><br><span class="line">select a.* ,b.s_score <span class="keyword">as</span> <span class="number">01</span>_score,c.s_score <span class="keyword">as</span> <span class="number">02</span>_score <span class="keyword">from</span> </span><br><span class="line">student a </span><br><span class="line">	join score b on a.s_id=b.s_id and b.c_id=<span class="string">'01'</span></span><br><span class="line">	left join score c on a.s_id=c.s_id and c.c_id=<span class="string">'02'</span> or c.c_id = NULL where b.s_score&gt;c.s_score</span><br><span class="line">	</span><br><span class="line">--也可以这样写</span><br><span class="line">	select a.*,b.s_score <span class="keyword">as</span> <span class="number">01</span>_score,c.s_score <span class="keyword">as</span> <span class="number">02</span>_score <span class="keyword">from</span> student 		  a,score b,score c </span><br><span class="line">			where a.s_id=b.s_id </span><br><span class="line">			and a.s_id=c.s_id </span><br><span class="line">			and b.c_id=<span class="string">'01'</span> </span><br><span class="line">			and c.c_id=<span class="string">'02'</span> </span><br><span class="line">			and b.s_score&gt;c.s_score</span><br><span class="line">-- <span class="number">2</span>、查询<span class="string">"01"</span>课程比<span class="string">"02"</span>课程成绩低的学生的信息及课程分数</span><br><span class="line">	</span><br><span class="line">select a.* ,b.s_score <span class="keyword">as</span> <span class="number">01</span>_score,c.s_score <span class="keyword">as</span> <span class="number">02</span>_score <span class="keyword">from</span> </span><br><span class="line">	student a left join score b on a.s_id=b.s_id and b.c_id=<span class="string">'01'</span> or b.c_id=NULL </span><br><span class="line">	 join score c on a.s_id=c.s_id and c.c_id=<span class="string">'02'</span> where b.s_score&lt;c.s_score</span><br><span class="line">			</span><br><span class="line"></span><br><span class="line">-- <span class="number">3</span>、查询平均成绩大于等于<span class="number">60</span>分的同学的学生编号和学生姓名和平均成绩</span><br><span class="line">select b.s_id,b.s_name,ROUND(AVG(a.s_score),<span class="number">2</span>) <span class="keyword">as</span> avg_score <span class="keyword">from</span> </span><br><span class="line">	student b </span><br><span class="line">	join score a on b.s_id = a.s_id</span><br><span class="line">	GROUP BY b.s_id,b.s_name HAVING avg_score &gt;=<span class="number">60</span>;</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line">-- <span class="number">4</span>、查询平均成绩小于<span class="number">60</span>分的同学的学生编号和学生姓名和平均成绩</span><br><span class="line">		-- (包括有成绩的和无成绩的)</span><br><span class="line">		</span><br><span class="line">select b.s_id,b.s_name,ROUND(AVG(a.s_score),<span class="number">2</span>) <span class="keyword">as</span> avg_score <span class="keyword">from</span> </span><br><span class="line">	student b </span><br><span class="line">	left join score a on b.s_id = a.s_id</span><br><span class="line">	GROUP BY b.s_id,b.s_name HAVING avg_score &lt;<span class="number">60</span></span><br><span class="line">	union</span><br><span class="line">select a.s_id,a.s_name,<span class="number">0</span> <span class="keyword">as</span> avg_score <span class="keyword">from</span> </span><br><span class="line">	student a </span><br><span class="line">	where a.s_id not <span class="keyword">in</span> (</span><br><span class="line">				select distinct s_id <span class="keyword">from</span> score);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- <span class="number">5</span>、查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩</span><br><span class="line">select a.s_id,a.s_name,count(b.c_id) <span class="keyword">as</span> sum_course,sum(b.s_score) <span class="keyword">as</span> sum_score <span class="keyword">from</span> </span><br><span class="line">	student a </span><br><span class="line">	left join score b on a.s_id=b.s_id</span><br><span class="line">	GROUP BY a.s_id,a.s_name;</span><br><span class="line">			</span><br><span class="line">			</span><br><span class="line">-- <span class="number">6</span>、查询<span class="string">"李"</span>姓老师的数量 </span><br><span class="line">select count(t_id) <span class="keyword">from</span> teacher where t_name like <span class="string">'李%'</span>;</span><br><span class="line">	</span><br><span class="line">-- <span class="number">7</span>、查询学过<span class="string">"张三"</span>老师授课的同学的信息 </span><br><span class="line">select a.* <span class="keyword">from</span> </span><br><span class="line">	student a </span><br><span class="line">	join score b on a.s_id=b.s_id where b.c_id <span class="keyword">in</span>(</span><br><span class="line">		select c_id <span class="keyword">from</span> course where t_id =(</span><br><span class="line">			select t_id <span class="keyword">from</span> teacher where t_name = <span class="string">'张三'</span>));</span><br><span class="line"></span><br><span class="line">-- <span class="number">8</span>、查询没学过<span class="string">"张三"</span>老师授课的同学的信息 </span><br><span class="line">select * <span class="keyword">from</span> </span><br><span class="line">    student c </span><br><span class="line">    where c.s_id not <span class="keyword">in</span>(</span><br><span class="line">        select a.s_id <span class="keyword">from</span> student a join score b on a.s_id=b.s_id where b.c_id <span class="keyword">in</span>(</span><br><span class="line">        select a.c_id <span class="keyword">from</span> course a join teacher b on a.t_id = b.t_id where t_name =<span class="string">'张三'</span>));</span><br><span class="line">-- <span class="number">9</span>、查询学过编号为<span class="string">"01"</span>并且也学过编号为<span class="string">"02"</span>的课程的同学的信息</span><br><span class="line"></span><br><span class="line">select a.* <span class="keyword">from</span> </span><br><span class="line">	student a,score b,score c </span><br><span class="line">	where a.s_id = b.s_id  and a.s_id = c.s_id and b.c_id=<span class="string">'01'</span> and c.c_id=<span class="string">'02'</span>;</span><br><span class="line">	</span><br><span class="line">-- <span class="number">10</span>、查询学过编号为<span class="string">"01"</span>但是没有学过编号为<span class="string">"02"</span>的课程的同学的信息</span><br><span class="line">			</span><br><span class="line">select a.* <span class="keyword">from</span> </span><br><span class="line">	student a </span><br><span class="line">	where a.s_id <span class="keyword">in</span> (select s_id <span class="keyword">from</span> score where c_id=<span class="string">'01'</span> ) and a.s_id not <span class="keyword">in</span>(select s_id <span class="keyword">from</span> score where c_id=<span class="string">'02'</span>)</span><br><span class="line">			</span><br><span class="line"></span><br><span class="line">-- <span class="number">11</span>、查询没有学全所有课程的同学的信息 </span><br><span class="line">--@wendiepei的写法</span><br><span class="line">select s.* <span class="keyword">from</span> student s </span><br><span class="line">left join Score s1 on s1.s_id=s.s_id</span><br><span class="line">group by s.s_id having count(s1.c_id)&lt;(select count(*) <span class="keyword">from</span> course)	</span><br><span class="line">--@k1051785839的写法</span><br><span class="line">select *</span><br><span class="line"><span class="keyword">from</span> student</span><br><span class="line">where s_id not <span class="keyword">in</span>(</span><br><span class="line">select s_id <span class="keyword">from</span> score t1  </span><br><span class="line">group by s_id having count(*) =(select count(distinct c_id)  <span class="keyword">from</span> course)) </span><br><span class="line">-- <span class="number">12</span>、查询至少有一门课与学号为<span class="string">"01"</span>的同学所学相同的同学的信息 </span><br><span class="line"></span><br><span class="line">select * <span class="keyword">from</span> student where s_id <span class="keyword">in</span>(</span><br><span class="line">	select distinct a.s_id <span class="keyword">from</span> score a where a.c_id <span class="keyword">in</span>(select a.c_id <span class="keyword">from</span> score a where a.s_id=<span class="string">'01'</span>)</span><br><span class="line">	);</span><br><span class="line">			</span><br><span class="line">-- <span class="number">13</span>、查询和<span class="string">"01"</span>号的同学学习的课程完全相同的其他同学的信息 </span><br><span class="line">--@ouyang_1993的写法</span><br><span class="line">SELECT</span><br><span class="line"> Student.*</span><br><span class="line">FROM</span><br><span class="line"> Student</span><br><span class="line">WHERE</span><br><span class="line"> s_id IN (SELECT s_id FROM Score GROUP BY s_id HAVING COUNT(s_id) = (</span><br><span class="line">    #下面的语句是找到'01'同学学习的课程数</span><br><span class="line">    SELECT COUNT(c_id) FROM Score WHERE s_id = <span class="string">'01'</span></span><br><span class="line">   )</span><br><span class="line"> )</span><br><span class="line">AND s_id NOT IN (</span><br><span class="line"> #下面的语句是找到学过‘01’同学没学过的课程，有哪些同学。并排除他们</span><br><span class="line"> SELECT s_id FROM Score</span><br><span class="line"> WHERE c_id IN(</span><br><span class="line">   #下面的语句是找到‘01’同学没学过的课程</span><br><span class="line">   SELECT DISTINCT c_id FROM Score</span><br><span class="line">   WHERE c_id NOT IN (</span><br><span class="line">     #下面的语句是找出‘01’同学学习的课程</span><br><span class="line">     SELECT c_id FROM Score WHERE s_id = <span class="string">'01'</span></span><br><span class="line">    )</span><br><span class="line">  ) GROUP BY s_id</span><br><span class="line">) #下面的条件是排除01同学</span><br><span class="line">AND s_id NOT IN (<span class="string">'01'</span>)</span><br><span class="line">--@k1051785839的写法</span><br><span class="line">SELECT</span><br><span class="line"> t3.*</span><br><span class="line">FROM</span><br><span class="line"> (</span><br><span class="line">  SELECT</span><br><span class="line">   s_id,</span><br><span class="line">   group_concat(c_id ORDER BY c_id) group1</span><br><span class="line">  FROM</span><br><span class="line">   score</span><br><span class="line">  WHERE</span><br><span class="line">   s_id &amp;lt;&gt; <span class="string">'01'</span></span><br><span class="line">  GROUP BY</span><br><span class="line">   s_id</span><br><span class="line"> ) t1</span><br><span class="line">INNER JOIN (</span><br><span class="line"> SELECT</span><br><span class="line">  group_concat(c_id ORDER BY c_id) group2</span><br><span class="line"> FROM</span><br><span class="line">  score</span><br><span class="line"> WHERE</span><br><span class="line">  s_id = <span class="string">'01'</span></span><br><span class="line"> GROUP BY</span><br><span class="line">  s_id</span><br><span class="line">) t2 ON t1.group1 = t2.group2</span><br><span class="line">INNER JOIN student t3 ON t1.s_id = t3.s_id</span><br><span class="line"></span><br><span class="line">-- <span class="number">14</span>、查询没学过<span class="string">"张三"</span>老师讲授的任一门课程的学生姓名 </span><br><span class="line">select a.s_name <span class="keyword">from</span> student a where a.s_id not <span class="keyword">in</span> (</span><br><span class="line">	select s_id <span class="keyword">from</span> score where c_id = </span><br><span class="line">				(select c_id <span class="keyword">from</span> course where t_id =(</span><br><span class="line">					select t_id <span class="keyword">from</span> teacher where t_name = <span class="string">'张三'</span>)));</span><br><span class="line"></span><br><span class="line">-- <span class="number">15</span>、查询两门及其以上不及格课程的同学的学号，姓名及其平均成绩 </span><br><span class="line">select a.s_id,a.s_name,ROUND(AVG(b.s_score)) <span class="keyword">from</span> </span><br><span class="line">	student a </span><br><span class="line">	left join score b on a.s_id = b.s_id</span><br><span class="line">	where a.s_id <span class="keyword">in</span>(</span><br><span class="line">			select s_id <span class="keyword">from</span> score where s_score&lt;<span class="number">60</span> GROUP BY  s_id having count(<span class="number">1</span>)&gt;=<span class="number">2</span>)</span><br><span class="line">	GROUP BY a.s_id,a.s_name</span><br><span class="line"></span><br><span class="line">-- <span class="number">16</span>、检索<span class="string">"01"</span>课程分数小于<span class="number">60</span>，按分数降序排列的学生信息</span><br><span class="line">select a.*,b.c_id,b.s_score <span class="keyword">from</span> </span><br><span class="line">	student a,score b </span><br><span class="line">	where a.s_id = b.s_id and b.c_id=<span class="string">'01'</span> and b.s_score&lt;<span class="number">60</span> ORDER BY b.s_score DESC;</span><br><span class="line">		</span><br><span class="line">-- <span class="number">17</span>、按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩</span><br><span class="line">select a.s_id,(select s_score <span class="keyword">from</span> score where s_id=a.s_id and c_id=<span class="string">'01'</span>) <span class="keyword">as</span> 语文,</span><br><span class="line">				(select s_score <span class="keyword">from</span> score where s_id=a.s_id and c_id=<span class="string">'02'</span>) <span class="keyword">as</span> 数学,</span><br><span class="line">				(select s_score <span class="keyword">from</span> score where s_id=a.s_id and c_id=<span class="string">'03'</span>) <span class="keyword">as</span> 英语,</span><br><span class="line">			round(avg(s_score),<span class="number">2</span>) <span class="keyword">as</span> 平均分 <span class="keyword">from</span> score a  GROUP BY a.s_id ORDER BY 平均分 DESC;</span><br><span class="line">--@喝完这杯还有一箱的写法</span><br><span class="line">SELECT a.s_id,MAX(CASE a.c_id WHEN <span class="string">'01'</span> THEN a.s_score END ) 语文, </span><br><span class="line">MAX(CASE a.c_id WHEN <span class="string">'02'</span> THEN a.s_score END ) 数学, </span><br><span class="line">MAX(CASE a.c_id WHEN <span class="string">'03'</span> THEN a.s_score END ) 英语, </span><br><span class="line">avg(a.s_score),b.s_name FROM Score a JOIN Student b ON a.s_id=b.s_id GROUP BY a.s_id ORDER BY <span class="number">5</span> DESC		</span><br><span class="line">-- <span class="number">18.</span>查询各科成绩最高分、最低分和平均分：以如下形式显示：课程ID，课程name，最高分，最低分，平均分，及格率，中等率，优良率，优秀率</span><br><span class="line">--及格为&gt;=<span class="number">60</span>，中等为：<span class="number">70</span><span class="number">-80</span>，优良为：<span class="number">80</span><span class="number">-90</span>，优秀为：&gt;=<span class="number">90</span></span><br><span class="line">select a.c_id,b.c_name,MAX(s_score),MIN(s_score),ROUND(AVG(s_score),<span class="number">2</span>),</span><br><span class="line">	ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when a.s_score&gt;=<span class="number">60</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/SUM(<span class="keyword">case</span> when a.s_score then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)),<span class="number">2</span>) <span class="keyword">as</span> 及格率,</span><br><span class="line">	ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when a.s_score&gt;=<span class="number">70</span> and a.s_score&lt;=<span class="number">80</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/SUM(<span class="keyword">case</span> when a.s_score then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)),<span class="number">2</span>) <span class="keyword">as</span> 中等率,</span><br><span class="line">	ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when a.s_score&gt;=<span class="number">80</span> and a.s_score&lt;=<span class="number">90</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/SUM(<span class="keyword">case</span> when a.s_score then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)),<span class="number">2</span>) <span class="keyword">as</span> 优良率,</span><br><span class="line">	ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when a.s_score&gt;=<span class="number">90</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/SUM(<span class="keyword">case</span> when a.s_score then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)),<span class="number">2</span>) <span class="keyword">as</span> 优秀率</span><br><span class="line">	<span class="keyword">from</span> score a left join course b on a.c_id = b.c_id GROUP BY a.c_id,b.c_name</span><br><span class="line">	</span><br><span class="line">-- <span class="number">19</span>、按各科成绩进行排序，并显示排名</span><br><span class="line">-- mysql没有rank函数</span><br><span class="line">	select a.s_id,a.c_id,</span><br><span class="line">        @i:=@i +<span class="number">1</span> <span class="keyword">as</span> i保留排名,</span><br><span class="line">        @k:=(<span class="keyword">case</span> when @score=a.s_score then @k <span class="keyword">else</span> @i end) <span class="keyword">as</span> rank不保留排名,</span><br><span class="line">        @score:=a.s_score <span class="keyword">as</span> score</span><br><span class="line">    <span class="keyword">from</span> (</span><br><span class="line">        select s_id,c_id,s_score <span class="keyword">from</span> score GROUP BY s_id,c_id,s_score ORDER BY s_score DESC</span><br><span class="line">)a,(select @k:=<span class="number">0</span>,@i:=<span class="number">0</span>,@score:=<span class="number">0</span>)s</span><br><span class="line">--@k1051785839的写法</span><br><span class="line">(select * <span class="keyword">from</span> (select </span><br><span class="line">t1.c_id,</span><br><span class="line">t1.s_score,</span><br><span class="line">(select count(distinct t2.s_score) <span class="keyword">from</span> score t2 where t2.s_score&gt;=t1.s_score and t2.c_id=<span class="string">'01'</span>) rank</span><br><span class="line">FROM score t1 where t1.c_id=<span class="string">'01'</span></span><br><span class="line">order by t1.s_score desc) t1)</span><br><span class="line">union</span><br><span class="line">(select * <span class="keyword">from</span> (select </span><br><span class="line">t1.c_id,</span><br><span class="line">t1.s_score,</span><br><span class="line">(select count(distinct t2.s_score) <span class="keyword">from</span> score t2 where t2.s_score&gt;=t1.s_score and t2.c_id=<span class="string">'02'</span>) rank</span><br><span class="line">FROM score t1 where t1.c_id=<span class="string">'02'</span></span><br><span class="line">order by t1.s_score desc) t2)</span><br><span class="line">union</span><br><span class="line">(select * <span class="keyword">from</span> (select </span><br><span class="line">t1.c_id,</span><br><span class="line">t1.s_score,</span><br><span class="line">(select count(distinct t2.s_score) <span class="keyword">from</span> score t2 where t2.s_score&gt;=t1.s_score and t2.c_id=<span class="string">'03'</span>) rank</span><br><span class="line">FROM score t1 where t1.c_id=<span class="string">'03'</span></span><br><span class="line">order by t1.s_score desc) t3)</span><br><span class="line">-- <span class="number">20</span>、查询学生的总成绩并进行排名</span><br><span class="line">select a.s_id,</span><br><span class="line">	@i:=@i+<span class="number">1</span> <span class="keyword">as</span> i,</span><br><span class="line">	@k:=(<span class="keyword">case</span> when @score=a.sum_score then @k <span class="keyword">else</span> @i end) <span class="keyword">as</span> rank,</span><br><span class="line">	@score:=a.sum_score <span class="keyword">as</span> score</span><br><span class="line"><span class="keyword">from</span> (select s_id,SUM(s_score) <span class="keyword">as</span> sum_score <span class="keyword">from</span> score GROUP BY s_id ORDER BY sum_score DESC)a,</span><br><span class="line">	(select @k:=<span class="number">0</span>,@i:=<span class="number">0</span>,@score:=<span class="number">0</span>)s</span><br><span class="line">	</span><br><span class="line">-- <span class="number">21</span>、查询不同老师所教不同课程平均分从高到低显示 </span><br><span class="line">		</span><br><span class="line">	select a.t_id,c.t_name,a.c_id,ROUND(avg(s_score),<span class="number">2</span>) <span class="keyword">as</span> avg_score <span class="keyword">from</span> course a</span><br><span class="line">		left join score b on a.c_id=b.c_id </span><br><span class="line">		left join teacher c on a.t_id=c.t_id</span><br><span class="line">		GROUP BY a.c_id,a.t_id,c.t_name ORDER BY avg_score DESC;</span><br><span class="line">-- <span class="number">22</span>、查询所有课程的成绩第<span class="number">2</span>名到第<span class="number">3</span>名的学生信息及该课程成绩</span><br><span class="line">			</span><br><span class="line">			select d.*,c.排名,c.s_score,c.c_id <span class="keyword">from</span> (</span><br><span class="line">                select a.s_id,a.s_score,a.c_id,@i:=@i+<span class="number">1</span> <span class="keyword">as</span> 排名 <span class="keyword">from</span> score a,(select @i:=<span class="number">0</span>)s where a.c_id=<span class="string">'01'</span>  </span><br><span class="line">								ORDER BY a.s_score DESC  </span><br><span class="line">            )c</span><br><span class="line">            left join student d on c.s_id=d.s_id</span><br><span class="line">            where 排名 BETWEEN <span class="number">2</span> AND <span class="number">3</span></span><br><span class="line">            UNION</span><br><span class="line">            select d.*,c.排名,c.s_score,c.c_id <span class="keyword">from</span> (</span><br><span class="line">                select a.s_id,a.s_score,a.c_id,@j:=@j+<span class="number">1</span> <span class="keyword">as</span> 排名 <span class="keyword">from</span> score a,(select @j:=<span class="number">0</span>)s where a.c_id=<span class="string">'02'</span>  </span><br><span class="line">								ORDER BY a.s_score DESC</span><br><span class="line">            )c</span><br><span class="line">            left join student d on c.s_id=d.s_id</span><br><span class="line">            where 排名 BETWEEN <span class="number">2</span> AND <span class="number">3</span></span><br><span class="line">            UNION</span><br><span class="line">            select d.*,c.排名,c.s_score,c.c_id <span class="keyword">from</span> (</span><br><span class="line">                select a.s_id,a.s_score,a.c_id,@k:=@k+<span class="number">1</span> <span class="keyword">as</span> 排名 <span class="keyword">from</span> score a,(select @k:=<span class="number">0</span>)s where a.c_id=<span class="string">'03'</span> </span><br><span class="line">								ORDER BY a.s_score DESC</span><br><span class="line">            )c</span><br><span class="line">            left join student d on c.s_id=d.s_id</span><br><span class="line">            where 排名 BETWEEN <span class="number">2</span> AND <span class="number">3</span>;</span><br><span class="line">			</span><br><span class="line">-- <span class="number">23</span>、统计各科成绩各分数段人数：课程编号,课程名称,[<span class="number">100</span><span class="number">-85</span>],[<span class="number">85</span><span class="number">-70</span>],[<span class="number">70</span><span class="number">-60</span>],[<span class="number">0</span><span class="number">-60</span>]及所占百分比</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">		select distinct f.c_name,a.c_id,b.<span class="string">`85-100`</span>,b.百分比,c.<span class="string">`70-85`</span>,c.百分比,d.<span class="string">`60-70`</span>,d.百分比,e.<span class="string">`0-60`</span>,e.百分比 <span class="keyword">from</span> score a</span><br><span class="line">				left join (select c_id,SUM(<span class="keyword">case</span> when s_score &gt;<span class="number">85</span> and s_score &lt;=<span class="number">100</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end) <span class="keyword">as</span> <span class="string">`85-100`</span>,</span><br><span class="line">											ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when s_score &gt;<span class="number">85</span> and s_score &lt;=<span class="number">100</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/count(*)),<span class="number">2</span>) <span class="keyword">as</span> 百分比</span><br><span class="line">								<span class="keyword">from</span> score GROUP BY c_id)b on a.c_id=b.c_id</span><br><span class="line">				left join (select c_id,SUM(<span class="keyword">case</span> when s_score &gt;<span class="number">70</span> and s_score &lt;=<span class="number">85</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end) <span class="keyword">as</span> <span class="string">`70-85`</span>,</span><br><span class="line">											ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when s_score &gt;<span class="number">70</span> and s_score &lt;=<span class="number">85</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/count(*)),<span class="number">2</span>) <span class="keyword">as</span> 百分比</span><br><span class="line">								<span class="keyword">from</span> score GROUP BY c_id)c on a.c_id=c.c_id</span><br><span class="line">				left join (select c_id,SUM(<span class="keyword">case</span> when s_score &gt;<span class="number">60</span> and s_score &lt;=<span class="number">70</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end) <span class="keyword">as</span> <span class="string">`60-70`</span>,</span><br><span class="line">											ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when s_score &gt;<span class="number">60</span> and s_score &lt;=<span class="number">70</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/count(*)),<span class="number">2</span>) <span class="keyword">as</span> 百分比</span><br><span class="line">								<span class="keyword">from</span> score GROUP BY c_id)d on a.c_id=d.c_id</span><br><span class="line">				left join (select c_id,SUM(<span class="keyword">case</span> when s_score &gt;=<span class="number">0</span> and s_score &lt;=<span class="number">60</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end) <span class="keyword">as</span> <span class="string">`0-60`</span>,</span><br><span class="line">											ROUND(<span class="number">100</span>*(SUM(<span class="keyword">case</span> when s_score &gt;=<span class="number">0</span> and s_score &lt;=<span class="number">60</span> then <span class="number">1</span> <span class="keyword">else</span> <span class="number">0</span> end)/count(*)),<span class="number">2</span>) <span class="keyword">as</span> 百分比</span><br><span class="line">								<span class="keyword">from</span> score GROUP BY c_id)e on a.c_id=e.c_id</span><br><span class="line">				left join course f on a.c_id = f.c_id</span><br><span class="line">				 </span><br><span class="line">-- <span class="number">24</span>、查询学生平均成绩及其名次 </span><br><span class="line"></span><br><span class="line">		select a.s_id,</span><br><span class="line">				@i:=@i+<span class="number">1</span> <span class="keyword">as</span> <span class="string">'不保留空缺排名'</span>,</span><br><span class="line">				@k:=(<span class="keyword">case</span> when @avg_score=a.avg_s then @k <span class="keyword">else</span> @i end) <span class="keyword">as</span> <span class="string">'保留空缺排名'</span>,</span><br><span class="line">				@avg_score:=avg_s <span class="keyword">as</span> <span class="string">'平均分'</span></span><br><span class="line">		<span class="keyword">from</span> (select s_id,ROUND(AVG(s_score),<span class="number">2</span>) <span class="keyword">as</span> avg_s <span class="keyword">from</span> score GROUP BY s_id ORDER BY avg_s DESC)a,(select @avg_score:=<span class="number">0</span>,@i:=<span class="number">0</span>,@k:=<span class="number">0</span>)b;</span><br><span class="line">-- <span class="number">25</span>、查询各科成绩前三名的记录</span><br><span class="line">			-- <span class="number">1.</span>选出b表比a表成绩大的所有组</span><br><span class="line">			-- <span class="number">2.</span>选出比当前id成绩大的 小于三个的</span><br><span class="line">		select a.s_id,a.c_id,a.s_score <span class="keyword">from</span> score a </span><br><span class="line">			left join score b on a.c_id = b.c_id and a.s_score&lt;b.s_score</span><br><span class="line">			group by a.s_id,a.c_id,a.s_score HAVING COUNT(b.s_id)&lt;<span class="number">3</span></span><br><span class="line">			ORDER BY a.c_id,a.s_score DESC</span><br><span class="line"></span><br><span class="line">-- <span class="number">26</span>、查询每门课程被选修的学生数 </span><br><span class="line"></span><br><span class="line">		select c_id,count(s_id) <span class="keyword">from</span> score a GROUP BY c_id</span><br><span class="line"></span><br><span class="line">-- <span class="number">27</span>、查询出只有两门课程的全部学生的学号和姓名 </span><br><span class="line">		select s_id,s_name <span class="keyword">from</span> student where s_id <span class="keyword">in</span>(</span><br><span class="line">				select s_id <span class="keyword">from</span> score GROUP BY s_id HAVING COUNT(c_id)=<span class="number">2</span>);</span><br><span class="line"></span><br><span class="line">-- <span class="number">28</span>、查询男生、女生人数 </span><br><span class="line">		select s_sex,COUNT(s_sex) <span class="keyword">as</span> 人数  <span class="keyword">from</span> student GROUP BY s_sex</span><br><span class="line"></span><br><span class="line">-- <span class="number">29</span>、查询名字中含有<span class="string">"风"</span>字的学生信息</span><br><span class="line"></span><br><span class="line">		select * <span class="keyword">from</span> student where s_name like <span class="string">'%风%'</span>;</span><br><span class="line"></span><br><span class="line">-- <span class="number">30</span>、查询同名同性学生名单，并统计同名人数 </span><br><span class="line">		</span><br><span class="line">		select a.s_name,a.s_sex,count(*) <span class="keyword">from</span> student a  JOIN </span><br><span class="line">					student b on a.s_id !=b.s_id and a.s_name = b.s_name and a.s_sex = b.s_sex</span><br><span class="line">		GROUP BY a.s_name,a.s_sex</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- <span class="number">31</span>、查询<span class="number">1990</span>年出生的学生名单</span><br><span class="line">		</span><br><span class="line">		select s_name <span class="keyword">from</span> student where s_birth like <span class="string">'1990%'</span></span><br><span class="line"></span><br><span class="line">-- <span class="number">32</span>、查询每门课程的平均成绩，结果按平均成绩降序排列，平均成绩相同时，按课程编号升序排列 </span><br><span class="line"></span><br><span class="line">	select c_id,ROUND(AVG(s_score),<span class="number">2</span>) <span class="keyword">as</span> avg_score <span class="keyword">from</span> score GROUP BY c_id ORDER BY avg_score DESC,c_id ASC</span><br><span class="line"></span><br><span class="line">-- <span class="number">33</span>、查询平均成绩大于等于<span class="number">85</span>的所有学生的学号、姓名和平均成绩 </span><br><span class="line"></span><br><span class="line">	select a.s_id,b.s_name,ROUND(avg(a.s_score),<span class="number">2</span>) <span class="keyword">as</span> avg_score <span class="keyword">from</span> score a</span><br><span class="line">		left join student b on a.s_id=b.s_id GROUP BY s_id HAVING avg_score&gt;=<span class="number">85</span></span><br><span class="line">	</span><br><span class="line">-- <span class="number">34</span>、查询课程名称为<span class="string">"数学"</span>，且分数低于<span class="number">60</span>的学生姓名和分数 </span><br><span class="line">	</span><br><span class="line">		select a.s_name,b.s_score <span class="keyword">from</span> score b join student a on a.s_id=b.s_id where b.c_id=(</span><br><span class="line">					select c_id <span class="keyword">from</span> course where c_name =<span class="string">'数学'</span>) and b.s_score&lt;<span class="number">60</span></span><br><span class="line"></span><br><span class="line">-- <span class="number">35</span>、查询所有学生的课程及分数情况； </span><br><span class="line">	</span><br><span class="line">		</span><br><span class="line">		select a.s_id,a.s_name,</span><br><span class="line">					SUM(<span class="keyword">case</span> c.c_name when <span class="string">'语文'</span> then b.s_score <span class="keyword">else</span> <span class="number">0</span> end) <span class="keyword">as</span> <span class="string">'语文'</span>,</span><br><span class="line">					SUM(<span class="keyword">case</span> c.c_name when <span class="string">'数学'</span> then b.s_score <span class="keyword">else</span> <span class="number">0</span> end) <span class="keyword">as</span> <span class="string">'数学'</span>,</span><br><span class="line">					SUM(<span class="keyword">case</span> c.c_name when <span class="string">'英语'</span> then b.s_score <span class="keyword">else</span> <span class="number">0</span> end) <span class="keyword">as</span> <span class="string">'英语'</span>,</span><br><span class="line">					SUM(b.s_score) <span class="keyword">as</span>  <span class="string">'总分'</span></span><br><span class="line">		<span class="keyword">from</span> student a left join score b on a.s_id = b.s_id </span><br><span class="line">		left join course c on b.c_id = c.c_id </span><br><span class="line">		GROUP BY a.s_id,a.s_name</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"> -- <span class="number">36</span>、查询任何一门课程成绩在<span class="number">70</span>分以上的姓名、课程名称和分数； </span><br><span class="line">			select a.s_name,b.c_name,c.s_score <span class="keyword">from</span> course b left join score c on b.c_id = c.c_id</span><br><span class="line">				left join student a on a.s_id=c.s_id where c.s_score&gt;=<span class="number">70</span></span><br><span class="line"></span><br><span class="line">		</span><br><span class="line"></span><br><span class="line">-- <span class="number">37</span>、查询不及格的课程</span><br><span class="line">		select a.s_id,a.c_id,b.c_name,a.s_score <span class="keyword">from</span> score a left join course b on a.c_id = b.c_id</span><br><span class="line">			where a.s_score&lt;<span class="number">60</span> </span><br><span class="line">		</span><br><span class="line">-<span class="number">-38</span>、查询课程编号为<span class="number">01</span>且课程成绩在<span class="number">80</span>分以上的学生的学号和姓名； </span><br><span class="line">		select a.s_id,b.s_name <span class="keyword">from</span> score a LEFT JOIN student b on a.s_id = b.s_id</span><br><span class="line">			where a.c_id = <span class="string">'01'</span>	and a.s_score&gt;<span class="number">80</span></span><br><span class="line"></span><br><span class="line">-- <span class="number">39</span>、求每门课程的学生人数 </span><br><span class="line">		select count(*) <span class="keyword">from</span> score GROUP BY c_id;</span><br><span class="line"></span><br><span class="line">-- <span class="number">40</span>、查询选修<span class="string">"张三"</span>老师所授课程的学生中，成绩最高的学生信息及其成绩</span><br><span class="line"></span><br><span class="line">		</span><br><span class="line">		-- 查询老师id	</span><br><span class="line">		select c_id <span class="keyword">from</span> course c,teacher d where c.t_id=d.t_id and d.t_name=<span class="string">'张三'</span></span><br><span class="line">		-- 查询最高分（可能有相同分数）</span><br><span class="line">		select MAX(s_score) <span class="keyword">from</span> score where c_id=<span class="string">'02'</span></span><br><span class="line">		-- 查询信息</span><br><span class="line">		select a.*,b.s_score,b.c_id,c.c_name <span class="keyword">from</span> student a</span><br><span class="line">			LEFT JOIN score b on a.s_id = b.s_id</span><br><span class="line">			LEFT JOIN course c on b.c_id=c.c_id</span><br><span class="line">			where b.c_id =(select c_id <span class="keyword">from</span> course c,teacher d where c.t_id=d.t_id and d.t_name=<span class="string">'张三'</span>)</span><br><span class="line">			and b.s_score <span class="keyword">in</span> (select MAX(s_score) <span class="keyword">from</span> score where c_id=<span class="string">'02'</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- <span class="number">41</span>、查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩 </span><br><span class="line">	select DISTINCT b.s_id,b.c_id,b.s_score <span class="keyword">from</span> score a,score b where a.c_id != b.c_id and a.s_score = b.s_score</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line">-- <span class="number">42</span>、查询每门功成绩最好的前两名 </span><br><span class="line">		-- 牛逼的写法</span><br><span class="line">	select a.s_id,a.c_id,a.s_score <span class="keyword">from</span> score a</span><br><span class="line">		where (select COUNT(<span class="number">1</span>) <span class="keyword">from</span> score b where b.c_id=a.c_id and b.s_score&gt;=a.s_score)&lt;=<span class="number">2</span> ORDER BY a.c_id</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- <span class="number">43</span>、统计每门课程的学生选修人数（超过<span class="number">5</span>人的课程才统计）。要求输出课程号和选修人数，查询结果按人数降序排列，若人数相同，按课程号升序排列  </span><br><span class="line">		select c_id,count(*) <span class="keyword">as</span> total <span class="keyword">from</span> score GROUP BY c_id HAVING total&gt;<span class="number">5</span> ORDER BY total,c_id ASC</span><br><span class="line">		</span><br><span class="line">-- <span class="number">44</span>、检索至少选修两门课程的学生学号 </span><br><span class="line">		select s_id,count(*) <span class="keyword">as</span> sel <span class="keyword">from</span> score GROUP BY s_id HAVING sel&gt;=<span class="number">2</span></span><br><span class="line"></span><br><span class="line">-- <span class="number">45</span>、查询选修了全部课程的学生信息 </span><br><span class="line">		select * <span class="keyword">from</span> student where s_id <span class="keyword">in</span>(		</span><br><span class="line">			select s_id <span class="keyword">from</span> score GROUP BY s_id HAVING count(*)=(select count(*) <span class="keyword">from</span> course))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-<span class="number">-46</span>、查询各学生的年龄</span><br><span class="line">	-- 按照出生日期来算，当前月日 &lt; 出生年月的月日则，年龄减一</span><br><span class="line"></span><br><span class="line">	select s_birth,(DATE_FORMAT(NOW(),<span class="string">'%Y'</span>)-DATE_FORMAT(s_birth,<span class="string">'%Y'</span>) - </span><br><span class="line">				(<span class="keyword">case</span> when DATE_FORMAT(NOW(),<span class="string">'%m%d'</span>)&gt;DATE_FORMAT(s_birth,<span class="string">'%m%d'</span>) then <span class="number">0</span> <span class="keyword">else</span> <span class="number">1</span> end)) <span class="keyword">as</span> age</span><br><span class="line">		<span class="keyword">from</span> student;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- <span class="number">47</span>、查询本周过生日的学生</span><br><span class="line">	select * <span class="keyword">from</span> student where WEEK(DATE_FORMAT(NOW(),<span class="string">'%Y%m%d'</span>))=WEEK(s_birth)</span><br><span class="line">	select * <span class="keyword">from</span> student where YEARWEEK(s_birth)=YEARWEEK(DATE_FORMAT(NOW(),<span class="string">'%Y%m%d'</span>))</span><br><span class="line">	</span><br><span class="line">	select WEEK(DATE_FORMAT(NOW(),<span class="string">'%Y%m%d'</span>))</span><br><span class="line"></span><br><span class="line">-- <span class="number">48</span>、查询下周过生日的学生</span><br><span class="line">	select * <span class="keyword">from</span> student where WEEK(DATE_FORMAT(NOW(),<span class="string">'%Y%m%d'</span>))+<span class="number">1</span> =WEEK(s_birth)</span><br><span class="line"></span><br><span class="line">-- <span class="number">49</span>、查询本月过生日的学生</span><br><span class="line"></span><br><span class="line">	select * <span class="keyword">from</span> student where MONTH(DATE_FORMAT(NOW(),<span class="string">'%Y%m%d'</span>)) =MONTH(s_birth)</span><br><span class="line">	</span><br><span class="line">-- <span class="number">50</span>、查询下月过生日的学生</span><br><span class="line">	select * <span class="keyword">from</span> student where MONTH(DATE_FORMAT(NOW(),<span class="string">'%Y%m%d'</span>))+<span class="number">1</span> =MONTH(s_birth)</span><br></pre></td></tr></table></figure>

<h3 id="数据库常用SQL语句"><a href="#数据库常用SQL语句" class="headerlink" title="数据库常用SQL语句"></a>数据库常用SQL语句</h3><h4 id="一、创建数据库"><a href="#一、创建数据库" class="headerlink" title="一、创建数据库"></a>一、创建数据库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">CREATE DATABASE database-name</span><br></pre></td></tr></table></figure>

<h4 id="二、删除数据库"><a href="#二、删除数据库" class="headerlink" title="二、删除数据库"></a>二、删除数据库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">drop database dbname</span><br></pre></td></tr></table></figure>

<h4 id="三、创建表"><a href="#三、创建表" class="headerlink" title="三、创建表"></a>三、创建表</h4><h5 id="1-直接创建"><a href="#1-直接创建" class="headerlink" title="1.直接创建"></a>1.直接创建</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">CREATE TABLE tabname</span><br><span class="line">(</span><br><span class="line"></span><br><span class="line">coll typel [NOT NULL] [AUTO_INCREMENT] [primary key] [COMMENT &#39;注释&#39;]</span><br><span class="line">)</span><br></pre></td></tr></table></figure>

<ul>
<li>coll：字段名</li>
<li>typel：数据类型</li>
<li>NOT NULL：约束强制列不接受 NULL 值</li>
<li>AUTO_INCREMENT：自增（搭配主键使用）</li>
<li>primary key：主键</li>
<li>COMMENT：注释</li>
</ul>
<h5 id="2-更具已有表创建"><a href="#2-更具已有表创建" class="headerlink" title="2.更具已有表创建"></a>2.更具已有表创建</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">create table tab_new like tab_old (使用旧表创建新表)</span><br><span class="line">create table tab_new as select col1,col2… from tab_old definition only</span><br></pre></td></tr></table></figure>

<h4 id="四、删除表"><a href="#四、删除表" class="headerlink" title="四、删除表"></a>四、删除表</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">drop table tabname</span><br></pre></td></tr></table></figure>

<h4 id="五、增加一列"><a href="#五、增加一列" class="headerlink" title="五、增加一列"></a>五、增加一列</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Alter table tabname add column col type</span><br></pre></td></tr></table></figure>

<h4 id="六、基本SQL语句"><a href="#六、基本SQL语句" class="headerlink" title="六、基本SQL语句"></a>六、基本SQL语句</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">--选择：</span><br><span class="line">        select * from table1 where 范围</span><br><span class="line"></span><br><span class="line">--插入：</span><br><span class="line">        insert into table1(field1,field2) values(value1,value2)</span><br><span class="line"></span><br><span class="line">--删除：</span><br><span class="line">        delete from table1 where 范围</span><br><span class="line"></span><br><span class="line">--更新：</span><br><span class="line">        update table1 set field1&#x3D;value1 where 范围</span><br><span class="line"></span><br><span class="line">--查找：</span><br><span class="line">        select * from table1 where field1 like ’%value1%’ ---like的语法很精妙，查资料!</span><br><span class="line"></span><br><span class="line">--排序：</span><br><span class="line">        select * from table1 order by field1,field2 [desc]</span><br><span class="line"></span><br><span class="line">--总数：</span><br><span class="line">        select count as totalcount from table1</span><br><span class="line"></span><br><span class="line">--求和：</span><br><span class="line">        select sum(field1) as sumvalue from table1</span><br><span class="line"></span><br><span class="line">--平均：</span><br><span class="line">        select avg(field1) as avgvalue from table1</span><br><span class="line"></span><br><span class="line">--最大：</span><br><span class="line">        select max(field1) as maxvalue from table1</span><br><span class="line"></span><br><span class="line">　　最小：select min(field1) as minvalue from table1</span><br></pre></td></tr></table></figure>


<h2 id="vue"><a href="#vue" class="headerlink" title="vue"></a>vue</h2><h3 id="vue-安装"><a href="#vue-安装" class="headerlink" title="vue 安装"></a>vue 安装</h3><blockquote>
<p>1.创建项目</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vue create &lt;项目名&gt;</span><br></pre></td></tr></table></figure>

<h3 id="store-的用法"><a href="#store-的用法" class="headerlink" title="store 的用法"></a>store 的用法</h3><ol>
<li><p>先在vuex/store/rootState.js 下编辑</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> state = &#123;</span><br><span class="line">    count: <span class="number">0</span>,</span><br><span class="line">    products:[</span><br><span class="line">        &#123;<span class="attr">name</span>:<span class="string">'apple'</span>, <span class="attr">price</span>: <span class="string">'2'</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">name</span>:<span class="string">'banana'</span>, <span class="attr">price</span>: <span class="string">'3'</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">name</span>:<span class="string">'pear'</span>, <span class="attr">price</span>: <span class="string">'4'</span>&#125;,</span><br><span class="line">        &#123;<span class="attr">name</span>:<span class="string">'melon'</span>, <span class="attr">price</span>: <span class="string">'5'</span>&#125;,</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> state;</span><br></pre></td></tr></table></figure></li>
<li><p>在页面中使用</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">this</span>.$store.state <span class="comment">//获取到state的值</span></span><br></pre></td></tr></table></figure></li>
<li><p>使用vuex的mutations的方法</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//调用increment方法</span></span><br><span class="line"><span class="keyword">this</span>.$store.commit(<span class="string">'increment'</span>)</span><br></pre></td></tr></table></figure></li>
<li><p>mutations方法</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  updateDirection (state, direction) &#123;</span><br><span class="line">    state.direction = direction</span><br><span class="line">  &#125;,</span><br><span class="line">  increment: <span class="function"><span class="params">state</span> =&gt;</span> state.count++,</span><br><span class="line">  decrement: <span class="function"><span class="params">state</span> =&gt;</span> state.count--</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>不同页面的对应不同的方法与store状态存储</p>
<ol>
<li>在modules引入对应的模块index<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> index <span class="keyword">from</span> <span class="string">'../modules/index/index'</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">		index</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>在index模块下<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">	<span class="keyword">import</span> * <span class="keyword">as</span> type <span class="keyword">from</span> <span class="string">'./mutations_types'</span></span><br><span class="line"><span class="keyword">import</span> &#123; Index &#125; <span class="keyword">from</span> <span class="string">'api/index'</span></span><br><span class="line"><span class="comment">// import &#123; Toast &#125; from 'mint-ui';</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">    namespaced: <span class="literal">true</span>,</span><br><span class="line">    state: &#123;</span><br><span class="line">        token: localStorage.getItem(<span class="string">'token'</span>) || <span class="string">''</span>,</span><br><span class="line">        user: <span class="built_in">JSON</span>.parse(localStorage.getItem(<span class="string">'userDate'</span>)) || &#123;&#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    mutations: &#123;</span><br><span class="line"></span><br><span class="line">        [type.GETINDEX](state, data) &#123;</span><br><span class="line">            <span class="keyword">let</span> userDate = data.data;</span><br><span class="line">            state.token = userDate.token;</span><br><span class="line">            state.user = userDate;</span><br><span class="line">            localStorage.setItem(<span class="string">'token'</span>, userDate.token)</span><br><span class="line">            localStorage.setItem(<span class="string">'userDate'</span>, <span class="built_in">JSON</span>.stringify(userDate))</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;,</span><br><span class="line">    actions: &#123;</span><br><span class="line">        <span class="keyword">async</span> login(state, data) &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                <span class="keyword">let</span> res = <span class="keyword">await</span> Index(&#123;</span><br><span class="line">                    username: data.username,</span><br><span class="line">                    password: data.password</span><br><span class="line">                &#125;)</span><br><span class="line">                state.commit(type.GETINDEX, res);</span><br><span class="line">                alert(<span class="string">'登录成功'</span>)</span><br><span class="line">                <span class="comment">// Toast(&#123;</span></span><br><span class="line">                <span class="comment">//     message: '登录成功',</span></span><br><span class="line">                <span class="comment">//     position: 'middle',</span></span><br><span class="line">                <span class="comment">//     duration: 2000</span></span><br><span class="line">                <span class="comment">// &#125;);</span></span><br><span class="line">                setTimeout(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">                    <span class="keyword">const</span> redirect = data.$route.query.redirect || <span class="string">'/'</span>;</span><br><span class="line">                    data.$router.replace(&#123;</span><br><span class="line">                        path: redirect</span><br><span class="line">                    &#125;)</span><br><span class="line">                &#125;, <span class="number">3000</span>);</span><br><span class="line">            &#125; <span class="keyword">catch</span> (error) &#123;</span><br><span class="line">                <span class="comment">//</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    getters: &#123;</span><br><span class="line">    &#125;</span><br><span class="line">	&#125;</span><br></pre></td></tr></table></figure>


</li>
</ol>
</li>
</ol>
<h2 id="JavaScript-1"><a href="#JavaScript-1" class="headerlink" title="JavaScript"></a>JavaScript</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">var</span> arr = [&#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"ZYTX"</span>,</span><br><span class="line">    <span class="string">"age"</span>: <span class="string">"Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix"</span>,</span><br><span class="line">    <span class="string">"gender"</span>: <span class="string">"AAAAAA.doc"</span></span><br><span class="line">&#125;, &#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"ZYTA"</span>,</span><br><span class="line">    <span class="string">"age"</span>: <span class="string">"Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix"</span>,</span><br><span class="line">    <span class="string">"gender"</span>: <span class="string">"BBBBBB.doc"</span></span><br><span class="line">&#125;, &#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"ZDTX"</span>,</span><br><span class="line">    <span class="string">"age"</span>: <span class="string">"Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix"</span>,</span><br><span class="line">    <span class="string">"gender"</span>: <span class="string">"CCCCCC.doc"</span></span><br><span class="line">&#125;, &#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"ZYTX"</span>,</span><br><span class="line">    <span class="string">"age"</span>: <span class="string">"Y13xG_4wQnOWK1QwJLgg11d0pS4hewePU95UHtpMl3eE81uS74NC-6zu-Rtnw4Ix"</span>,</span><br><span class="line">    <span class="string">"gender"</span>: <span class="string">"AAAAAA.doc"</span></span><br><span class="line">&#125;];</span><br><span class="line"><span class="keyword">var</span> hash = &#123;&#125;;</span><br><span class="line">arr = arr.reduce(<span class="function"><span class="keyword">function</span>(<span class="params">item, next</span>) </span>&#123;</span><br><span class="line">    hash[next.name] ? <span class="string">''</span> : hash[next.name] = <span class="literal">true</span> &amp;&amp; item.push(next);</span><br><span class="line">    <span class="keyword">return</span> item</span><br><span class="line">&#125;, [])</span><br><span class="line"><span class="built_in">console</span>.log(arr);</span><br></pre></td></tr></table></figure>



<h2 id="webpack"><a href="#webpack" class="headerlink" title="webpack"></a>webpack</h2><h2 id="NPM"><a href="#NPM" class="headerlink" title="NPM"></a>NPM</h2>
      
    </div>
    <div id="comments">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a style="word-wrap:break-word;" href="http://yoursite.com/20120/03/27/05/WEB/%E5%88%BB%E6%84%8F%E7%BB%83%E4%B9%A0/" title="刻意练习" target="_blank" rel="external">http://yoursite.com/20120/03/27/05/WEB/%E5%88%BB%E6%84%8F%E7%BB%83%E4%B9%A0/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/chen08" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/chen08" target="_blank"><span class="text-dark">溟海</span><small class="ml-1x">Web Developer &amp; Designer</small></a></h3>
        <div>天行健，君子以自强不息，地势坤，君子以厚德载物。 杀不死我的,终将使我强大 没有吃不了的苦,只有享不了的福</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/20120/03/27/05/%E6%B2%99%E7%9B%98%E4%B8%8E%E5%A4%8D%E7%9B%98/" title="沙盘与复盘"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;Newer</span></a>
    </li>
    
    
    <li class="next">
      <a href="/2020/05/08/01/Source-code/jquery%E6%BA%90%E7%A0%81%E5%AD%A6%E4%B9%A0/" title="vue基础"><span>Older&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="Catalogue" role="button">
        <span>[&nbsp;</span><span>Catalogue</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>$</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>Maybe you could buy me a cup of coffee.</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/images/donate/alipayimg.png" alt="Scan Qrcode" title="Scan" />
              </div>
              <p class="text-muted mv">Scan this qrcode</p>
              <p class="text-grey">Open alipay app scan this qrcode, buy me a coffee!</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/images/donate/wechatpayimg.png" alt="Scan Qrcode" title="Scan" />
              </div>
              <p class="text-muted mv">Scan this qrcode</p>
              <p class="text-grey">Open wechat app scan this qrcode, buy me a coffee!</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> alipay</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> wechat payment</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/cofess" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="http://weibo.com/cofess" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="https://twitter.com/iwebued" target="_blank" title="Twitter" data-toggle=tooltip data-placement=top><i class="icon icon-twitter"></i></a></li>
        
        <li><a href="https://www.behance.net/cofess" target="_blank" title="Behance" data-toggle=tooltip data-placement=top><i class="icon icon-behance"></i></a></li>
        
        <li><a href="/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/js/plugin.min.js"></script>


<script src="/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: 'Posts',
            PAGES: 'Pages',
            CATEGORIES: 'Categories',
            TAGS: 'Tags',
            UNTITLED: '(Untitled)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/js/insight.js"></script>






   


<!-- custom analytics part create by xiamo -->
<script  src="https://cdn1.lncld.net/static/js/av-min-1.2.1.js"></script>
<!-- <script defer src="/js/av-min-1.2.1.js"></script> -->
<script >
AV.init({
  appId: 'ngFQzHw7z0HgQfrtn4En4WTN-gzGzoHsz',
  appKey: 'W9hgBBfVDwRGJKoGp5a6HKpx'
});

function showTime(Counter) {
	var query = new AV.Query(Counter);
		var visitors= $('.leancloud_visitors');
		query.greaterThanOrEqualTo("time", 0);		
		query.find({
			success: function(results) {
				if (results.length == 0) {				
					return;
				}
				var data = results;
				visitors.each(function(){
					var url = $(this).attr('id').trim();					
					for (var i = 0; i < data.length; i++) {
						var object = data[i];
						var content = object.get('time');
						var _url = object.get('url')
						if(url == _url){
							$(this).text(content);
						}
					}
				})
				
			},
			error: function(object, error) {
				console.log("Error: " + error.code + " " + error.message);
			}
		});
}

function addCount(Counter) {
	var Counter = AV.Object.extend("Counter");
	url = $(".leancloud_visitors").attr('id').trim();
	title = $(".leancloud_visitors").attr('data-flag-title').trim();
	var query = new AV.Query(Counter);
	query.equalTo("url", url);
	query.find({
		success: function(results) {
			if (results.length > 0) {
				var counter = results[0];
				counter.fetchWhenSave(true);
				counter.increment("time");
				counter.save(null, {
					success: function(counter) {
						var content = counter.get('time');
						$(document.getElementById(url)).text(content);
					},
					error: function(counter, error) {
						console.log('Failed to save Visitor num, with error message: ' + error.message);
					}
				});
			} else {
				var newcounter = new Counter();
				newcounter.set("title", title);
				newcounter.set("url", url);
				newcounter.set("time", 1);
				newcounter.save(null, {
					success: function(newcounter) {
					    console.log("newcounter.get('time')="+newcounter.get('time'));
						var content = newcounter.get('time');
						$(document.getElementById(url)).text(content);
					},
					error: function(newcounter, error) {
						console.log('Failed to create');
					}
				});
			}
		},
		error: function(error) {
			console.log('Error:' + error.code + " " + error.message);
		}
	});
}
$(function() {
	var Counter = AV.Object.extend("Counter");
	if ($('.leancloud_visitors').length == 1) {
		addCount(Counter);
	} else {
		showTime(Counter);
	}
}); 
</script>



   
    
  <!-- <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script> -->
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>